• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Top Contributors Leaderboard 1.1.3

No permission to download

wdb

Active member
#1
wdb submitted a new resource:

Top Contributors Leaderboard (version 1.0) - Generates a monthly leaderboard of top contributors to the forum

Generates a monthly leaderboard of top contributors to the forum. The ranking is based on the sum of the messages posted and the likes those posts received in the given month.

To install copy the contents of the upload folder to the XenForo library folder, install the add-on via the xml file, add usergroup permissions to 'can view top users'

View attachment 31316
Read more about this resource...
 

ArnyVee

Well-known member
#2
Interesting .... could be used for a 'monthly contest' setup.

Can you add the ability for a custom timeframe rather than just monthly? This would be perfect :)

Thanks for sharing this. (y)
 

HWS

Well-known member
#3
After looking at the code, I would not recommend installing this addon except you have a very, very small forum.

Other forums will have a massive resource problem with the database calls this addon does at every single call of the leaderboard page.
 

wdb

Active member
#4
After looking at the code, I would not recommend installing this addon except you have a very, very small forum.

Other forums will have a massive resource problem with the database calls this addon does at every single call of the leaderboard page.
Yes it could be a bit of a hit on resources on a big database, working fine for me with 250k posts. That is why I added the usergroup permissions so you can prevent guests/bots from hammering the database.

Can you suggest any better way the query could be handled ?
 
R

ragtek

Guest
#5
i hadn't checked the query, but you shouldn't run the code(query) for people without permission to view the page...

Move the permission check to top and return a no perm error
PHP:
throw $this->getNoPermissionResponseException();
if the visitor doesn't have permissions
 

wdb

Active member
#6
i hadn't checked the query, but you shouldn't run the code(query) for people without permission to view the page...

Move the permission check to top and return a no perm error
PHP:
throw $this->getNoPermissionResponseException();
if the visitor doesn't have permissions
I don't think it does call the query for people without permission, the controller checks permission before calling the model. I'll try out your suggestion though as it looks like it may be more elegant than mine.
 
R

ragtek

Guest
#7
I don't think it does call the query for people without permission, the controller checks permission before calling the model. I'll try out your suggestion though as it looks like it may be more elegant than mine.
no

you're running getTopUsers even the user doesn't have perms

PHP:
class TopUsers_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
{
public function actionIndex()
{
$month_id = $this->_input->filterSingle('month_id', XenForo_Input::UINT);
 
$topUsers = $this->_getTopUsersModel()->getTopUsers($month_id);
 
$viewParams = array(
'topUsers' => $topUsers
);
 
if (XenForo_Visitor::getInstance()->hasPermission('topUsers', 'canViewTopUsers')) 
{
return $this->responseView('TopUsers_ViewPublic_Index', 'top_users_index', $viewParams);
} else {
return $this->responseView('TopUsers_ViewPublic_Index', 'top_users_index', array('canView'=>0));
}
}
 
#8
good work
if you plane to use this addon in forums with big database

you can run the sql query one time per day
PHP:
$users = $this->_getDb()->fetchAll('
                SELECT *, count(*) messages_delta, sum(likes) likes_delta, count(*) + sum(likes) score_delta
                FROM xf_post p JOIN xf_user u ON p.user_id=u.user_id JOIN xf_user_profile r on p.user_id=r.user_id
                WHERE  post_date > ? AND post_date < ?
                GROUP BY p.user_id
                ORDER BY score_delta DESC
                LIMIT 10;
                ', array($fromDate,$toDate));
store the result in a table
and show the Top Contributors from the table not directly from the sql query

thanks
 

wdb

Active member
#9
no

you're running getTopUsers even the user doesn't have perms

PHP:
class TopUsers_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
{
public function actionIndex()
{
$month_id = $this->_input->filterSingle('month_id', XenForo_Input::UINT);
 
$topUsers = $this->_getTopUsersModel()->getTopUsers($month_id);
 
$viewParams = array(
'topUsers' => $topUsers
);
 
if (XenForo_Visitor::getInstance()->hasPermission('topUsers', 'canViewTopUsers'))
{
return $this->responseView('TopUsers_ViewPublic_Index', 'top_users_index', $viewParams);
} else {
return $this->responseView('TopUsers_ViewPublic_Index', 'top_users_index', array('canView'=>0));
}
}

Ahh I see you are right, thanks for pointing that out, fixing it now.
 

HWS

Well-known member
#10
good work
if you plane to use this addon in forums with big database

you can run the sql query one time per day
PHP:
$users = $this->_getDb()->fetchAll('
                SELECT *, count(*) messages_delta, sum(likes) likes_delta, count(*) + sum(likes) score_delta
                FROM xf_post p JOIN xf_user u ON p.user_id=u.user_id JOIN xf_user_profile r on p.user_id=r.user_id
                WHERE  post_date > ? AND post_date < ?
                GROUP BY p.user_id
                ORDER BY score_delta DESC
                LIMIT 10;
                ', array($fromDate,$toDate));
store the result in a table
and show the Top Contributors from the table not directly from the sql query

thanks
Even if you run this query only once per day on a large forum, it will block your database for hours (if you use MYISAM) or need massive ressources (if you use InnoDB, as recommended).

If you really want statistical data for single months you need an extra table in the database where you store the posting and like count for each user in the row for the current month at the moment he/she is posting.
 

wdb

Active member
#11
good work
if you plane to use this addon in forums with big database

you can run the sql query one time per day
PHP:
$users = $this->_getDb()->fetchAll('
                SELECT *, count(*) messages_delta, sum(likes) likes_delta, count(*) + sum(likes) score_delta
                FROM xf_post p JOIN xf_user u ON p.user_id=u.user_id JOIN xf_user_profile r on p.user_id=r.user_id
                WHERE  post_date > ? AND post_date < ?
                GROUP BY p.user_id
                ORDER BY score_delta DESC
                LIMIT 10;
                ', array($fromDate,$toDate));
store the result in a table
and show the Top Contributors from the table not directly from the sql query

thanks
Hi, thanks for the tip that makes a lot of sense.
I will try and add caching, do you know if there is any special XenForo function I should be using or do I just create the table and read/write the cache using normal SQL queries ?
 
#12
Hi, thanks for the tip that makes a lot of sense.
I will try and add caching, do you know if there is any special XenForo function I should be using or do I just create the table and read/write the cache using normal SQL queries ?
you are welcom
for big forums you must enable caching
see here http://xenforo.com/community/threads/xenforo-caching-amazing.32629/#post-378974
for my suggestion keep it simple
just create the table and read/write the cache using normal SQL queries
and create Cron Entry that Automatically run once a day
http://xenforo.com/community/resources/how-to-create-a-cron-entry-to-move-threads-with-options.317/
 

wdb

Active member
#14
Caching should be implemented now. It would be good to hear what sort of performance people are seeing. On the forum I've been testing it on (>250k messages) an uncached page takes roughly 1 to 2 seconds longer for the browser to render than a forum thread, for a cached page there is no noticeable difference.
 

wdb

Active member
#17
Thank you for this but please let me know how to we would fix names of month in Turkish language?
See if this works:
Edit the file library/TopUsers/TopUsers.php

Find the line near the bottom
PHP:
$returnData['month_str'] = date('F-Y',$fromDate);
try replacing it with
PHP:
setlocale(LC_TIME, 'tr_TR');
$returnData['month_str'] = strftime('%B %Y',$fromDate);
if that doesn't work you can display a number instead of a month name with
PHP:
$returnData['month_str'] = date('m-Y',$fromDate);
 

Eagle

Well-known member
#18
See if this works:
Edit the file library/TopUsers/TopUsers.php

Find the line near the bottom
PHP:
$returnData['month_str'] = date('F-Y',$fromDate);
try replacing it with
PHP:
setlocale(LC_TIME, 'tr_TR');
$returnData['month_str'] = strftime('%B %Y',$fromDate);
if that doesn't work you can display a number instead of a month name with
PHP:
$returnData['month_str'] = date('m-Y',$fromDate);
Problem solved now thank you! : )
But I have a question; Why SEO is not working?
Thanks.
 

wdb

Active member
#19
Problem solved now thank you! : )
But I have a question; Why SEO is not working?
Thanks.

I think I see the problem, I will fix that in the next version.

the code near the top of the top_users_index template needs to look like this
Code:
<div class="topUsersSelection">
    <xen:if is="{$topUsers.month_down}">
        <a href="{xen:link 'top-users/{$topUsers.month_id_minus}'}"><div class="isSel">Previous Month</div></a>
    </xen:if>
    <xen:if is="{$topUsers.month_up}">
        <a href="{xen:link 'top-users/{$topUsers.month_id_plus}'}"><div class="isSel">Next Month</div></a>
    </xen:if>
</div>
actually I forgot to use phrases there too, I'll fix that also
 

Eagle

Well-known member
#20
Thank you again but now I see an another the problem.. When looking the page then "Viewing unknown page" on membercards or member profiles. You'd try it and see that problem.