Fixed Pagination breaks for admins if lots of deleted/unapproved resources

Jon W

Well-known member
Sorry to drop my first reported bug on release date (instead of when you had time to fix it before release date)...

When viewing all resources (i.e., latest, most downloaded, etc.), the total number of resources is calculated from the cached category counts, which do not include deleted/unapproved resources:
PHP:
$totalResources = 0;
foreach ($categories AS $category)
{
$totalResources += $category['resource_count'];
}

As such, if you have lots of deleted/unapproved resources (or even if you have 1 deleted/unapproved resource in a category with 21 resources), you may not be able to view all the resources without looking through all categories.

To make matters worse, unless every single resource has been deleted/unapproved (unlikely), you can't even try to access the hidden pages by adding ?page=2 etc., because the URL is canonicalised:
PHP:
$this->canonicalizePageNumber($page, $perPage, $totalResources, 'resources');
so you end up being bounced back to what it thinks is the last page.
 
I've fixed this now, though there's still an edge case I'm leaving for performance reasons. I'm using the category count unless you can see all deleted or moderated resources. The edge case is if you have a resource awaiting approval right now but you can only see your own. The count won't be bumped for that so it may be slightly off, but I think that's rare enough that it's worth saving the query to just run for moderators.
 
Back
Top Bottom