hgtonight / Application-Yaga

Yet Another Gamification Application is a Garden application that provides a gamification platform for Vanilla Forums and other Garden applications.
GNU General Public License v2.0
28 stars 23 forks source link

Best of... memory limit #76

Closed wolfgang1 closed 9 years ago

wolfgang1 commented 9 years ago

Hi! Thanks for your plugin! In the "best of" page some reactions and the "best of all time" show a blank page and when I activate the debugger I see the following message:

Fatal error: Allowed memory size of 52428800 bytes exhausted (tried to allocate 32 bytes) in .../forum/library/database/class.dataset.php on line 144

What can I do?

I'm running Vanilla 2.1.6 and the latest version of your plugin from vanilla forum page (the one released november 2014). My php version is .4

wolfgang1 commented 9 years ago

I've updated yaga to the latest version here on github and now also the best of the week page is not working.

bleistivt commented 9 years ago

You could try setting you php memory limit higher in your php.ini

memory_limit = 100M

The ActedModel doesn't really scale.

bleistivt commented 9 years ago

@hgtonight you can check out my experimental branch here:

https://github.com/bleistivt/Application-Yaga/commit/fd1918

It still doesn't scale, but should use a lot less memory

wolfgang1 commented 9 years ago

Bleistivt thanks for your reply. I can't change the php.ini file, our server administrator will not allow us to do so, he already complains about the amount of reasources we are using now! I'll try your experimental branch, or I can try to limit the amount of data retrieved, which php file control the query?

wolfgang1 commented 9 years ago

I've just tryied your patch. Yes the memory usage is more efficient! I should ask for merging! Now everything works exception made for the "best of the week", how is it possible that the best of recent consumes more memory than the best ever?

wolfgang1 commented 9 years ago

I'm not a PHP expert, but I've browsed the different functions and I've noticed that the "Best of Recent" is build differently form "Best of All Time". I don't understand why and it seems redundant. Wouldn't it be better to just add a "date filter" to "Best of All Time"? In that way you could actually create more options (Best of the week, month, etc.) with a simple click without the need to rebuild a table.

bleistivt commented 9 years ago

The "Best of Recent" works differently, it sorts by Reaction date rather than score. My patch doesn't cover that yet.

How big is your site? Or do your users write really long stories?

hgtonight commented 9 years ago

@bleistivt that patch is a great idea.

bleistivt commented 9 years ago

Just tested it on my own site using memory_get_usage() at beginning and at the end of the Get() function:

User with 1.4k reactions Without the patch:

start: 11 886 448
end:   38 241 856
       ----------
       26 355 408

With the patch

start: 11 889 592
end:   15 928 584
       ----------
        4 038 992

The number of records hasn't changed, so permissions etc. still work. (But we don't have a very complex permission system on the site.)

I could apply the same to the GetRecent() function and make a pull request. I'm unsure about my usage of GetRecord() though. What do you think about wrapping it in something like ActedModel->GetRecord() to make future optimizations / extensions possible?

wolfgang1 commented 9 years ago

@bleistivt My forum (a component of the site) has 1.300 users (active), 100.000 comments, 4.000 discussions and around 700.000 views. It has 3 years of activity. I've activated the yaga system since the 1st of january and by now I've recorded 10.000 reactions (only registered users with full membership = 20 points, 10 comments, 1 week of activity, can react) And yes there are also very long post (we basically don't have a limit, there are discussions who are biographies of users)

I've looked at the code this afternoon and I've realized that the "recent" works differently but I thought it was an unwanted feature @hgtonight ? I don't know if other communities works differently but we don't have "old posts", we have discussions active since the beginning of our activity with 2k+ replies but I don't want them to show in the best recent content. Is there any easy way to just filter out the discussions/comments with most points opened this week/month?

wolfgang1 commented 9 years ago

As I said before I'm not a PHP developer, but I've used a lot of DB for my work. If I could advance a suggestion for a better scaling: at the moment it seems to me that the reactions are linked to the users, so everytime you need a query to compute again the totals. Why simply don't create a table with: comment ID / reaction 1, reaction 2, etc.. with the totals already. You can easly create a "set-up" that update the table for backward compatibility and then each time a users react it update both the user-reaction table and that new table. In that way the "best-of" pages will scale far better. Because now it scales like users x comments x reactions, in that way it will simply scale with the number of comments.

wolfgang1 commented 9 years ago

Another note: The best of "reaction", doesn't take the "best of.." it simply show the latest reaction, so If I see in the "best of ever" I have a post with 15 "awesome", while in the best of "awesome" the first post is a post (very recent) with just one awesome.

wolfgang1 commented 9 years ago

The "super-coolness" would be to have the chance to personalize the "best of" with rules like you implemented with badges. But it is just a suggestion that will require a lot of work. If I'll find enough sponsorship for my forum in the next months maybe I can sponsor it :)

hgtonight commented 9 years ago

In my mind, the Best Of... specific reactions should be ugc where the majority of it's score is obtained from that reaction.

I am happy you have found some use for Yaga :)