Skip to content

Commit

Permalink
Various performance improvements (#3119)
Browse files Browse the repository at this point in the history
* Various performance improvements

* Remove debug

* Remove more debug

* Improve StaffCP total users widget
  • Loading branch information
samerton authored and Derkades committed Nov 18, 2022
1 parent a5f2114 commit 1829f08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions modules/Core/collections/panel/TotalUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public function __construct(Smarty $smarty, Language $language, Cache $cache) {

public function getContent(): string {
// Get the number of total users
$users_query = DB::getInstance()->get('users', ['id', '<>', 0])->results();
$users_query = DB::getInstance()->query('SELECT COUNT(*) AS c FROM nl2_users')->first()->c;

$this->_smarty->assign([
'TITLE' => $this->_language->get('admin', 'total_users'),
'VALUE' => count($users_query)
'VALUE' => $users_query
]);

return $this->_smarty->fetch('collections/dashboard_stats/total_users.tpl');
Expand Down
12 changes: 6 additions & 6 deletions modules/Forum/classes/Forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function listAllForums(array $groups = [0], int $user_id = 0): array {
SELECT *
FROM `nl2_forums`
WHERE `parent` = 0
AND `id` IN
AND `id` IN
(SELECT `forum_id`
FROM nl2_forums_permissions
WHERE `group_id` IN ($groups_in)
Expand All @@ -72,7 +72,7 @@ public function listAllForums(array $groups = [0], int $user_id = 0): array {
SELECT f.*
FROM nl2_forums AS f
WHERE f.parent = ?
AND f.id IN
AND f.id IN
(SELECT fp.forum_id
FROM nl2_forums_permissions AS fp
WHERE fp.group_id IN ($groups_in)
Expand Down Expand Up @@ -328,8 +328,8 @@ public function getLatestDiscussions(array $groups = [0], int $user_id = 0, int

return DB::getInstance()->query(
"SELECT topics.id as id, topics.forum_id as forum_id, topics.topic_title as topic_title, topics.topic_creator as topic_creator, topics.topic_last_user as topic_last_user, topics.topic_date as topic_date, topics.topic_reply_date as topic_reply_date, topics.topic_views as topic_views, topics.locked as locked, topics.sticky as sticky, topics.label as label, topics.deleted as deleted, posts.id as last_post_id
FROM nl2_topics topics
LEFT JOIN nl2_posts posts ON topics.id = posts.topic_id AND posts.id = (SELECT MAX(id) FROM nl2_posts p WHERE p.topic_id = topics.id AND p.deleted = 0)
FROM nl2_topics topics
LEFT JOIN nl2_posts posts ON topics.id = posts.topic_id AND posts.id = (SELECT MAX(id) FROM nl2_posts p WHERE p.topic_id = topics.id AND p.deleted = 0)
WHERE topics.deleted = 0 AND topics.forum_id IN (' . $all_topics_forums_string . ') ORDER BY topics.topic_reply_date DESC LIMIT $limit",
)->results();
}
Expand Down Expand Up @@ -399,7 +399,7 @@ public function updateForumLatestPosts(int $forum_id): void {
echo "Checking latest posts for $forum_id<br />";
$latest_post = $this->_db->query(
<<<SQL
SELECT `created`,
SELECT `created`,
`post_date`,
`post_creator`,
`topic_id`
Expand Down Expand Up @@ -434,7 +434,7 @@ public function updateForumLatestPosts(int $forum_id): void {
public function updateTopicLatestPosts(int $topic_id): void {
$latest_post = $this->_db->query(
<<<SQL
SELECT `created`,
SELECT `created`,
`post_date`,
`post_creator`
FROM nl2_posts
Expand Down

0 comments on commit 1829f08

Please sign in to comment.