Changed the unread check function to a counter.
This commit is contained in:
parent
696e646d6e
commit
c50f2a57d4
1 changed files with 10 additions and 14 deletions
|
@ -155,7 +155,7 @@ function forum_get_root_categories(int $userId): array
|
||||||
$categories[0]['forum_children'] = (int)($getRootForumCount->execute() ? $getRootForumCount->fetchColumn() : 0);
|
$categories[0]['forum_children'] = (int)($getRootForumCount->execute() ? $getRootForumCount->fetchColumn() : 0);
|
||||||
|
|
||||||
foreach ($categories as $key => $category) {
|
foreach ($categories as $key => $category) {
|
||||||
$categories[$key]['forum_unread'] = forum_read_status($category['forum_id'], $userId);
|
$categories[$key]['forum_unread'] = forum_topics_unread($category['forum_id'], $userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $categories;
|
return $categories;
|
||||||
|
@ -260,7 +260,7 @@ function forum_get_child_ids(int $forumId): array
|
||||||
return array_column($children, 'forum_id');
|
return array_column($children, 'forum_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
function forum_read_status(int $forumId, int $userId): bool
|
function forum_topics_unread(int $forumId, int $userId): int
|
||||||
{
|
{
|
||||||
if ($userId < 1 || $forumId < 1) {
|
if ($userId < 1 || $forumId < 1) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -273,15 +273,14 @@ function forum_read_status(int $forumId, int $userId): bool
|
||||||
return $memoized[$memoId];
|
return $memoized[$memoId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$memoized[$memoId] = 0;
|
||||||
$children = forum_get_child_ids($forumId);
|
$children = forum_get_child_ids($forumId);
|
||||||
|
|
||||||
foreach ($children as $child) {
|
foreach ($children as $child) {
|
||||||
if (forum_read_status($child, $userId)) {
|
$memoized[$memoId] += forum_topics_unread($child, $userId);
|
||||||
return $memoized[$memoId] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$checkStatus = db_prepare('
|
$countUnread = db_prepare('
|
||||||
SELECT COUNT(ti.`topic_id`)
|
SELECT COUNT(ti.`topic_id`)
|
||||||
FROM `msz_forum_topics` AS ti
|
FROM `msz_forum_topics` AS ti
|
||||||
LEFT JOIN `msz_forum_topics_track` AS tt
|
LEFT JOIN `msz_forum_topics_track` AS tt
|
||||||
|
@ -294,14 +293,11 @@ function forum_read_status(int $forumId, int $userId): bool
|
||||||
OR tt.`track_last_read` < ti.`topic_bumped`
|
OR tt.`track_last_read` < ti.`topic_bumped`
|
||||||
)
|
)
|
||||||
');
|
');
|
||||||
$checkStatus->bindValue('forum_id', $forumId);
|
$countUnread->bindValue('forum_id', $forumId);
|
||||||
$checkStatus->bindValue('user_id', $userId);
|
$countUnread->bindValue('user_id', $userId);
|
||||||
|
$memoized[$memoId] += (int)($countUnread->execute() ? $countUnread->fetchColumn() : 0);
|
||||||
|
|
||||||
if ($checkStatus->execute() ? $checkStatus->fetchColumn() : false) {
|
return $memoized[$memoId];
|
||||||
return $memoized[$memoId] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $memoized[$memoId] = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
define(
|
define(
|
||||||
|
@ -396,7 +392,7 @@ function forum_get_children(int $parentId, int $userId, bool $showDeleted = fals
|
||||||
$listing = db_fetch_all($getListing);
|
$listing = db_fetch_all($getListing);
|
||||||
|
|
||||||
foreach ($listing as $key => $forum) {
|
foreach ($listing as $key => $forum) {
|
||||||
$listing[$key]['forum_unread'] = forum_read_status($forum['forum_id'], $userId);
|
$listing[$key]['forum_unread'] = forum_topics_unread($forum['forum_id'], $userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $listing;
|
return $listing;
|
||||||
|
|
Loading…
Add table
Reference in a new issue