stephpy / timeline-bundle

Symfony2 bundle to make timeline
193 stars 57 forks source link

prefer using hash in ActionManager::findOrCreateComponent #212

Closed shouze closed 5 years ago

shouze commented 5 years ago

Pain point

when the table grows a lot (million of lines), hash is an indexed column while model and identifier are not 😢 .

The sadness resides in this picture: image

Change proposal

The happiness resides in this picture ⚡️ 🦄 🎉 image (1)

So, to implement that, I suggest to change ActionManager::findOrCreateComponent() implementation to use the hash:

https://github.com/stephpy/timeline-bundle/blob/e408d9d17a811e74c51ddcb9f03d8aa8fdc5a583/Driver/ORM/ActionManager.php#L77-L98

    public function findOrCreateComponent($model, $identifier = null, $flush = true)
    {
        $resolvedComponentData = $this->resolveModelAndIdentifier($model, $identifier);
        $component = $this->getComponentRepository()
            ->createQueryBuilder('c')
            ->where('c.hash = :hash')
           // Imply to add getHash method into https://github.com/stephpy/timeline/blob/d059ba3c2ffbefc2ec6d8ac68c7d6037b890b487/src/ResolveComponent/ValueObject/ResolveComponentModelIdentifier.php
            ->setParameter('hash', $resolvedComponentData->getHash())
            ->getQuery()
            ->getOneOrNullResult()
        ;
        if ($component) {
            $component->setData($resolvedComponentData->getData());
            return $component;
        }
        return $this->createComponentFromResolvedComponentData($resolvedComponentData, $flush);
    }
shouze commented 5 years ago

closed by https://github.com/stephpy/timeline/pull/49 & https://github.com/stephpy/timeline-bundle/pull/213