Skip to content

Commit

Permalink
remove Format::catalog* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Spine authored and itismadness committed Aug 15, 2021
1 parent 061df41 commit 3a2d873
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
13 changes: 0 additions & 13 deletions classes/format.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,6 @@ public static function page_limit($PerPage, $DefaultResult = 1) {
return [$Page, $Limit];
}

// A9 magic. Some other poor soul can write the phpdoc.
// For data stored in memcached catalogues (giant arrays), e.g. forum threads
public static function catalogue_limit($Page, $PerPage, $CatalogueSize = 500) {
$CatalogueID = floor(($PerPage * $Page - $PerPage) / $CatalogueSize);
$CatalogueLimit = ($CatalogueID * $CatalogueSize).", $CatalogueSize";
return [$CatalogueID, $CatalogueLimit];
}

public static function catalogue_select($Catalogue, $Page, $PerPage, $CatalogueSize = 500) {
return array_slice($Catalogue, (($PerPage * $Page - $PerPage) % $CatalogueSize), $PerPage, true);
}


/* Get pages
* Returns a page list, given certain information about the pages.
*
Expand Down
8 changes: 4 additions & 4 deletions sections/ajax/forum/thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
if (($Page - 1) * $PerPage > $threadInfo['Posts']) {
$Page = ceil($threadInfo['Posts'] / $PerPage);
}
[$CatalogueID, $CatalogueLimit] = Format::catalogue_limit($Page, $PerPage, THREAD_CATALOGUE);

// Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
$CatalogueID = floor(($PerPage * ($Page - 1)) / THREAD_CATALOGUE);
if (!$Catalogue = $Cache->get_value("thread_$threadId"."_catalogue_$CatalogueID")) {
$DB->prepared_query("
SELECT
Expand All @@ -86,15 +86,15 @@
FROM forums_posts AS p
WHERE p.TopicID = ?
AND p.ID != ?
LIMIT ?
", $threadId, $threadInfo['StickyPostID'], $CatalogueLimit
LIMIT ? OFFSET ?
", $threadId, $threadInfo['StickyPostID'], THREAD_CATALOGUE, $CatalogueID * $CatalogueSize
);
$Catalogue = $DB->to_array(false, MYSQLI_ASSOC);
if (!$threadInfo['isLocked'] || $threadInfo['isSticky']) {
$Cache->cache_value("thread_$threadId"."_catalogue_$CatalogueID", $Catalogue, 0);
}
}
$Thread = Format::catalogue_select($Catalogue, $Page, $PerPage, THREAD_CATALOGUE);
$Thread = array_slice($Catalogue, ($PerPage * ($Page - 1)) % THREAD_CATALOGUE, $PerPage, true);

if ($_GET['updatelastread'] !== '0') {
$LastPost = end($Thread);
Expand Down

0 comments on commit 3a2d873

Please sign in to comment.