[opw-web] Cache user info lookups
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [opw-web] Cache user info lookups
- Date: Mon, 10 Mar 2014 04:32:18 +0000 (UTC)
commit da1d152857d8c8b0976d50437b1523cd716c3617
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Sun Mar 9 12:45:53 2014 -0400
Cache user info lookups
classes/class_user.php | 41 +++++++++++++++++++++++++----------------
1 files changed, 25 insertions(+), 16 deletions(-)
---
diff --git a/classes/class_user.php b/classes/class_user.php
index 32cff00..108efd5 100644
--- a/classes/class_user.php
+++ b/classes/class_user.php
@@ -258,23 +258,30 @@ class user
function lookup_user($username)
{
- global $db;
-
- // Get current session data
- $sql = "SELECT is_admin, fullname, email FROM {$db->prefix}profiles " .
- "WHERE username = ?";
- $row = $db->query($sql, $username, true);
- if ($row === false) {
- return null;
- } else {
- $values = array();
-
- $values['is_admin'] = $row['is_admin'] != 0;
- $values['fullname'] = $row['fullname'];
- $values['email'] = $row['email'];
-
- return $values;
+ global $db, $cache;
+
+ $key = 'user_' . $username;
+ $values = $cache->get($key, 'users');
+
+ if ($values == false) {
+ // Get current session data
+ $sql = "SELECT is_admin, fullname, email FROM {$db->prefix}profiles " .
+ "WHERE username = ?";
+ $row = $db->query($sql, $username, true);
+ if ($row === false) {
+ return null;
+ } else {
+ $values = array();
+
+ $values['is_admin'] = $row['is_admin'] != 0;
+ $values['fullname'] = $row['fullname'];
+ $values['email'] = $row['email'];
+
+ $cache->put($key, $values, 'users');
+ }
}
+
+ return $values;
}
function create_user($provider, $identifier, $profile)
@@ -342,6 +349,8 @@ class user
"(provider, identifier, username) " .
"VALUES (:provider, :identifier, :username)";
$db->query($sql, $params);
+
+ $cache->purge('users');
}
function finish_login($provider)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]