From: Florent Bruneau Date: Sat, 15 Sep 2007 22:19:46 +0000 (+0200) Subject: Lighter query to get the number of events displaid on every single page of X-Git-Tag: xorg/0.9.15~150 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=e15dcc03aed9dceb1f5c0fbf2d73a2a3aa8945c9;p=platal.git Lighter query to get the number of events displaid on every single page of the site. Signed-off-by: Florent Bruneau --- diff --git a/include/notifs.inc.php b/include/notifs.inc.php index 4295b16..77dd994 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -53,6 +53,45 @@ function register_watch_op($uid, $cid, $date='', $info='') } // }}} +// {{{ function _select_notifs_count + +function _select_notifs_count($table) +{ + $cases = Array( + 'contacts' => Array('wfield' => 'contact', + 'ufield' => 'user_id', + 'freq_sql' => '', + 'where' => 'AND (q.watch_flags=1 OR q.watch_flags=3)' + ), + 'watch_promo' => Array('wfield' => 'promo', + 'ufield' => 'promo', + 'freq_sql' => ' AND ( wc.type = "basic" OR wc.type="near" + AND (u.promo <= v.promo_sortie-2 AND u.promo_sortie >= v.promo+2) )', + 'where' => '', + ), + 'watch_nonins' => Array('wfield' => 'ni_id', + 'ufield' => 'user_id', + 'freq_sql' => '', + 'where' => '', + ) + ); + $our = $cases[$table]; + $sql = " + ( + SELECT COUNT(1) AS count + FROM $table AS w + INNER JOIN auth_user_md5 AS u ON(u.{$our['ufield']} = w.{$our['wfield']}) + INNER JOIN auth_user_quick AS q ON(q.user_id = w.uid) + INNER JOIN auth_user_md5 AS v ON(v.user_id = q.user_id) + INNER JOIN watch_ops AS wo ON(wo.uid = u.user_id AND wo.known > q.watch_last) + INNER JOIN watch_sub AS ws ON(ws.cid = wo.cid AND ws.uid = w.uid) + INNER JOIN watch_cat AS wc ON(wc.id = wo.cid{$our['freq_sql']}) + WHERE w.uid = {?} {$our['where']} + )"; + return $sql; +} + +// }}} // {{{ function _select_notifs_base function _select_notifs_base($table, $mail, $where) @@ -137,14 +176,14 @@ function getNbNotifs() if (!S::has('uid')) { return 0; } - $uid = S::v('uid', -1); - $watchlast = S::v('watch_last'); + $uid = S::i('uid'); // selectionne les notifs de uid, sans detail sur le watcher, depuis // $watchlast, meme ceux sans surveillance, non ordonnés - $res = select_notifs(false, $uid, $watchlast, false); - $n = $res->numRows(); - $res->free(); + $res = XDB::query(_select_notifs_count('contacts') . ' UNION DISTINCT ' + . _select_notifs_count('watch_promo') . ' UNION DISTINCT ' + . _select_notifs_count('watch_nonins'), $uid, $uid, $uid); + $n = array_sum($res->fetchColumn()); if ($n == 0) { return; } diff --git a/plugins/insert.getNbIns.php b/plugins/insert.getNbIns.php index f19ff89..8cf3b2e 100644 --- a/plugins/insert.getNbIns.php +++ b/plugins/insert.getNbIns.php @@ -30,7 +30,7 @@ */ function smarty_insert_getNbIns($params, &$smarty) { - $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE perms IN ('admin','user') AND deces=0"); + $res = XDB::query("SELECT COUNT(1) FROM auth_user_md5 WHERE perms IN ('admin','user') AND deces=0"); $cnt = $res->fetchOneCell(); return number_format($cnt, 0, ",", "."); } diff --git a/plugins/insert.getNbNotifs.php b/plugins/insert.getNbNotifs.php index 3da1aad..ad6b8cd 100644 --- a/plugins/insert.getNbNotifs.php +++ b/plugins/insert.getNbNotifs.php @@ -22,9 +22,9 @@ function smarty_insert_getNbNotifs($params, &$smarty) { - if(S::logged()) { - require_once('notifs.inc.php'); - return getNbNotifs(); + if (S::logged()) { + require_once('notifs.inc.php'); + return getNbNotifs(); } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: