From: Florent Bruneau Date: Sat, 6 Oct 2007 20:52:39 +0000 (+0200) Subject: Revert "Lighter query to get the number of events displaid on every single X-Git-Tag: xorg/0.9.15~59 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=46d33a91589ed724a2b3b4c1fe742f4c892af32c;p=platal.git Revert "Lighter query to get the number of events displaid on every single page of the site". It introduced a bug in event count. This reverts commit e15dcc03aed9dceb1f5c0fbf2d73a2a3aa8945c9, and partially revert b4ee37a403aa5970304b447b31a747e47f9efb18 Conflicts: include/notifs.inc.php Signed-off-by: Florent Bruneau --- diff --git a/include/notifs.inc.php b/include/notifs.inc.php index 74348eb..b77bd34 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -53,45 +53,6 @@ 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) @@ -176,14 +137,14 @@ function getNbNotifs() if (!S::has('uid')) { return 0; } - $uid = S::i('uid'); + $uid = S::v('uid', -1); + $watchlast = S::v('watch_last'); // selectionne les notifs de uid, sans detail sur le watcher, depuis // $watchlast, meme ceux sans surveillance, non ordonnés - $res = XDB::query(_select_notifs_count('contacts') . ' UNION ' - . _select_notifs_count('watch_promo') . ' UNION ' - . _select_notifs_count('watch_nonins'), $uid, $uid, $uid); - $n = array_sum($res->fetchColumn()); + $res = select_notifs(false, $uid, $watchlast, false); + $n = $res->numRows(); + $res->free(); if ($n == 0) { return; } diff --git a/plugins/insert.getNbIns.php b/plugins/insert.getNbIns.php index 8cf3b2e..f19ff89 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(1) FROM auth_user_md5 WHERE perms IN ('admin','user') AND deces=0"); + $res = XDB::query("SELECT COUNT(*) 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 ad6b8cd..3da1aad 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: