We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36875
    • 5 Posts
    I am building a site where you can do a search for registered users and view their profiles. For this I wrote a ’GetSearchResults’ snippet.

    I fetch the users like this:

    		
    $myQuery = $modx->newQuery('modUser');
    $myQuery->leftJoin('modUserProfile', 'Profile');  //class, alias
    $myQuery->leftJoin('modUserGroupMember', 'UserGroupMembers');  
    $myQuery->where(array(
      'modUser.active' => 1,
      'UserGroupMembers.user_group' => 2
    ));
    $gtusers = $modx->getCollection('modUser', $myQuery);
    


    Filtering happens in PHP. Because it seems unnecessary to do the database operation over and over again, I thought I’d add this:

    $modx->cacheManager->set('GTUSERS', $gtusers)


    However, this gives me: Fatal error: Nesting level too deep - recursive dependency? in /customers/4/c/1/geregistreerdetolken.nl/httpd.www/core/xpdo/cache/xpdocachemanager.class.php on line 878

    I tried to var_dump the $gtusers array but that sort of froze my browser. What I could see is that the array is enormous and it seems filled with entries that have nothing to do with a user and his profile, like all kinds of config settings and lexicon entries and other stuff that I didn’t even recognize.

    The search function worked fine until I tried to cache results, so the query must be doing what I want it to. But it seems I get a lot of additional and unwanted results with it, if that makes any sense. And I guess this makes the overall search result so bloated that it causes the cachemanager to stumble. Why is this happening? What did I pluck from the database to create this gigantic array? And is there any way to narrow it down?
      • 3749
      • 24,544 Posts
      getCollection takes a third argument: $cacheflag (int) -- number of seconds to cache the result, though the results are cached by default so I’m not sure you need to do anything.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting