[TYPO3-mvc] DataMapper performance issue.

Braulio J. Solano-Rojas braulio at solsoft.biz
Fri Mar 30 04:28:47 CEST 2012


Hi Jochen,

El 29/03/2012 07:37 p.m., Jochen Rau escribió:
> 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}.

Hey, thanks, less code.  :-)

>
>> 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.

It is an excellent idea!  I am going to do that.  I did not know that 
ORDER BY RAND() was possible.  Just learned something.  :-)

Thanks for sharing your knowledge and ideas.

There should be a Tx_Extbase_Persistence_QueryInterface::ORDER_RANDOM. ;-)

[...]

>>> 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 ;-)

Yes, although we can always find some excuse like latin-america is poor 
therefore the server is a 486.  LOL  Just kidding!

Actually the result of being @lazy is at http://163.178.101.233/revista/ 
and it is really fast compared to before (at least from here).

>> 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).

Where can I find a thorough documentation about that?  I tried Google 
but I guess I am not using the correct keywords.

Bests,

B.



More information about the TYPO3-project-typo3v4mvc mailing list