[TYPO3-mvc] DataMapper performance issue.

Jochen Rau jochen.rau at typo3.org
Fri Mar 30 03:37:01 CEST 2012


Hi Braulio,

On Thu, Mar 29, 2012 at 05:55:58PM -0600, Braulio J. Solano-Rojas wrote:
> >It would be interesting to see your domain model and/or the queries you
> >call.
> 
> Of course.  In fact, I was thinking that my report was not
> descriptive enough and I was going to send another email.
> 
> The action that does that is a randomArticles action in an articles
> controller:
> 
>     public function randomArticlesAction() {
>         $lastEdition = $this->editionRepository->findLast();
>         if ($lastEdition) {
>             $lastEditionArticles = $lastEdition->getArticles()->toArray();
>             shuffle($lastEditionArticles);
>             $randomArticles = array();
>             for ($i=0; ($i<$this->settings['randomArticles']) &&
> ($i<count($lastEditionArticles)); $i++) {
>                 $randomArticles[] = $lastEditionArticles[$i];
>             }
>             $this->view->assign('edition', $lastEdition);
>             $this->view->assign('randomArticles', $randomArticles);
>             $this->view->assign('contentPageUid',
> $this->settings['contentPageUid']);
>         }
>     }

Just a side-note: The settings should be available in the view using {settings.contentPageUid}.

> There is an edition repository that has the method findLast above:
> 
>     public function findLast() {
>         $query = $this->createQuery();
>         $editions = $query->matching($query->equals('lastEdition', 1))
>             ->setOrderings(array('crdate' =>
> Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING))
>             ->setLimit(1)
>             ->execute();
>         return (count($editions) == 0) ? NULL : $editions->getFirst();
>     }


You could also perform a native SQL query like:

$query->statement("SELECT uid FROM tx_foo_article a INNER JOIN tx_foo_edition e ON ....... WHERE .... ORDER BY RAND() LIMIT 4;")->execute();

and use the uids to query for the article objects.

[...]

> I did not.  I am going to be more @lazy.  :-D

But not too lazy ;-)

Adding @lazy to Article->edition should improve performance as this
prevents you from loading the edition with all the articles with their
edition with all the articles with their edition with all the ...

You should *not* add lazy to Edition->articles because you have to load
them anyways. Otherwise this might lead to cripple loading and a drop in
performance.

> >Apart from that: Can't you cache the output of your extension? (And I
> >know that this can't be the solution to everything, but I've seen a lot
> >of uncached Extbase plugins where it wasn't needed)
> 
> I can.  In fact I am using the Netcreators Static Cache extension.
> However, for that specific action I can't because it is the front
> page of a magazine and the user requirements were that this page had
> to have four random article headers.  I forbade to cache that action
> in my extension's localconf.  You can see the effect at
> http://revista.inie.ucr.ac.cr/.

As this is the front page of a university it definitely has to be performant ;-)

> In a related subject, what is the effect of using the caching
> framework?  Will it cache only objects from queries or will it cache
> output too?

There are several levels of caching in TYPO3. One can decide to cache
- the whole page,
- output of a plugin,
- output of a template rendering,
- results of an object inspection (aka reflection),
- etc.

Other parts of the system might have a cache as well (like the database internals for example).

-Jochen


More information about the TYPO3-project-typo3v4mvc mailing list