symfony - Million ManyToMany Entries - Memory Problems -
i develope type of "statistics-web".
for example have blog entries , each visitor statistic entry.
example blog entity:
/** * @orm\manytomany(targetentity="statistic", inversedby="blogid") * @orm\jointable(name="blog_statistics") */ private $statistics;
example statistic entity:
/** * @orm\manytomany(targetentity="blog", mappedby="statistics") */ private $blog;
in entity statistic have more fields "time, user, ip". in blog entity have fields "text, title, time".
at beginning had 1 entry. working / good.
a week later, had 5.000 entries (db) 2 blog entries. (2.500 per blog entry) php memory problems.
i think doctrine tries load 2.500 entries ram/cache. need last 1 "last visited" information. rest of entries if needed them. (statistics overview)
whats best "limit" entries? current call: "repository->fetchall"
the solution pretty obvious:
$laststatisticsrecord = $repository->createquerybuilder('s') ->orderby('s.time', 'desc') ->setmaxresults(1) ->getquery() ->execute();
this query select last statistics entity table. if need blog entry last statistics entry, make join statement:
$laststatisticsrecord = $repository->createquerybuilder('s') ->select(array('s', 'b')) ->leftjoin('s.blogid', 'b') ->orderby('s.time', 'desc') ->setmaxresults(1) ->getquery() ->execute();
Comments
Post a Comment