Beispiel #1
0
function get_user($user_id)
{
    $user = db_execute('SELECT * FROM user WHERE id = ?', array($user_id))->fetch();
    if (!$user) {
        abort_content_not_found();
    }
    return $user;
}
Beispiel #2
0
function user_from_account($account_name)
{
    $user = db_execute('SELECT * FROM users WHERE account_name = ?', array($account_name))->fetch();
    if (!$user) {
        abort_content_not_found();
    }
    return $user;
}
Beispiel #3
0
function user_from_account($account_name)
{
    static $users = array();
    if (isset($users[$account_name])) {
        return $users[$account_name];
    }
    $key = 'isucon_user_' . $account_name;
    $cache = redis()->get($key);
    if ($cache !== false) {
        return $users[$account_name] = json_decode($cache, true);
    }
    $user = db_execute('SELECT * FROM users WHERE account_name = ?', array($account_name))->fetch();
    if (!$user) {
        abort_content_not_found();
    }
    redis()->set($key, json_encode($user));
    return $users[$account_name] = $user;
}