1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[ticket/13713] Cache SQL queries

PHPBB3-13713
This commit is contained in:
lavigor
2018-07-11 02:56:31 +03:00
committed by Marc Alexander
parent b5ce3343ed
commit 0aadd52014
9 changed files with 58 additions and 32 deletions

View File

@@ -76,10 +76,27 @@ abstract class base_user implements source_interface
public function get(array &$names, $keyword, $topic_id)
{
$keyword = utf8_clean_string($keyword);
$result = $this->db->sql_query_limit($this->query($keyword, $topic_id), self::NAMES_BATCH_SIZE);
while ($row = $this->db->sql_fetchrow($result))
// Do not query all possible users (just a moderate amount), cache results for 5 minutes
$result = $this->db->sql_query($this->query($keyword, $topic_id), 300);
$i = 0;
while ($i < self::NAMES_BATCH_SIZE)
{
$row = $this->db->sql_fetchrow($result);
if (!$row)
{
break;
}
if (!empty($keyword) && strpos($row['username_clean'], $keyword) !== 0)
{
continue;
}
$i++;
$user_rank = $this->user_loader->get_rank($row['user_id'], true);
array_push($names, [
'name' => $row['username'],
@@ -95,7 +112,5 @@ abstract class base_user implements source_interface
}
$this->db->sql_freeresult($result);
return $names;
}
}