refactor: messages and reports only loaded on pages where needed

#313
This commit is contained in:
Martin Ambrus
2017-11-17 21:00:00 +01:00
parent db87ce88a7
commit 6d0e95670b
4 changed files with 116 additions and 60 deletions
+24 -2
View File
@@ -677,8 +677,12 @@ class MYSQLi_DB implements IDbConnection {
* @return string Returns a sanitized string, safe for SQL queries.
*/
function escape($value) {
$value = stripslashes($value);
return mysqli_real_escape_string($this->dblink, $value);
if (is_string($value)) {
$value = stripslashes( $value );
return mysqli_real_escape_string($this->dblink, $value);
} else {
return $value;
}
}
/**
@@ -3636,6 +3640,24 @@ class MYSQLi_DB implements IDbConnection {
return mysqli_query($this->dblink,$q);
}
// no need to cache this method
function getUnreadMessagesCount($uid) {
$uid = (int) $uid;
return mysqli_fetch_array(mysqli_query($this->dblink, '
SELECT Count(*) as numUnread FROM '.TB_PREFIX.'mdata WHERE target = '.$uid.' AND viewed = 0'
), MYSQLI_ASSOC)['numUnread'];
}
// no need to cache this method
function getUnreadNoticesCount($uid) {
$uid = (int) $uid;
return mysqli_fetch_array(mysqli_query($this->dblink, '
SELECT Count(*) as numUnread FROM '.TB_PREFIX.'ndata WHERE uid = '.$uid.' AND viewed = 0'
), MYSQLI_ASSOC)['numUnread'];
}
function sendMessage($client, $owner, $topic, $message, $send, $alliance, $player, $coor, $report, $skip_escaping = false) {
if (!$skip_escaping) {
list($client, $owner, $topic, $message, $send, $alliance, $player, $coor, $report) = $this->escape_input((int) $client, (int) $owner, $topic, $message, (int) $send, (int) $alliance, (int) $player, (int) $coor, (int) $report);