From 723f316512bfd5b6990f2372c425c0a13a013ff4 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Oct 2020 17:05:36 +0000 Subject: [PATCH] avoid repeatedly fetching the same user when viewing PM list --- ext/pm/theme.php | 14 +++++++++++--- index.php | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ext/pm/theme.php b/ext/pm/theme.php index bb1e8346..22088fa0 100644 --- a/ext/pm/theme.php +++ b/ext/pm/theme.php @@ -6,6 +6,8 @@ class PrivMsgTheme extends Themelet { global $user; + $user_cache = []; + $html = " @@ -15,13 +17,18 @@ class PrivMsgTheme extends Themelet if (strlen(trim($h_subject)) == 0) { $h_subject = "(No subject)"; } - $from = User::by_id($pm->from_id); + if (!array_key_exists($pm->from_id, $user_cache)) { + $from = User::by_id($pm->from_id); + $user_cache[$pm->from_id] = $from; + } else { + $from = $user_cache[$pm->from_id]; + } $from_name = $from->name; $h_from = html_escape($from_name); $from_url = make_link("user/".url_escape($from_name)); $pm_url = make_link("pm/read/".$pm->id); $del_url = make_link("pm/delete"); - $h_date = html_escape($pm->sent_date); + $h_date = substr(html_escape($pm->sent_date), 0, 16); $readYN = "Y"; if (!$pm->is_read) { $h_subject = "$h_subject"; @@ -31,7 +38,8 @@ class PrivMsgTheme extends Themelet $html .= " - + +
R?SubjectFromDateAction
$readYN $h_subject$h_from$h_date$h_from$h_date
".$user->get_auth_html()." diff --git a/index.php b/index.php index 46a60f4b..8aa4ee43 100644 --- a/index.php +++ b/index.php @@ -101,6 +101,7 @@ try { if (TRACE_FILE) { if ( empty($_SERVER["REQUEST_URI"]) + || (@$_GET["trace"] == "on") || ( (microtime(true) - $_shm_load_start) > TRACE_THRESHOLD && ($_SERVER["REQUEST_URI"] ?? "") != "/upload"