aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
diff options
context:
space:
mode:
authorDhruv <dhruv.goel92@gmail.com>2014-06-01 13:38:27 +0530
committerDhruv <dhruv.goel92@gmail.com>2014-06-01 13:38:37 +0530
commit572debd0e820bfaa4d55b59eb19544fa245aa579 (patch)
tree4d37160e217e9f89f81a5aecd4a2c17a3e846e35 /phpBB/phpbb
parent48679eeff884ce564f7a5ceb7db1b6c64e5dcb67 (diff)
downloadforums-572debd0e820bfaa4d55b59eb19544fa245aa579.tar
forums-572debd0e820bfaa4d55b59eb19544fa245aa579.tar.gz
forums-572debd0e820bfaa4d55b59eb19544fa245aa579.tar.bz2
forums-572debd0e820bfaa4d55b59eb19544fa245aa579.tar.xz
forums-572debd0e820bfaa4d55b59eb19544fa245aa579.zip
[ticket/11445] Optimize no of queries in get_global_subscriptions
PHPBB3-11445
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r--phpBB/phpbb/notification/manager.php31
1 files changed, 18 insertions, 13 deletions
diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php
index c3539e76df..8378af2d99 100644
--- a/phpBB/phpbb/notification/manager.php
+++ b/phpBB/phpbb/notification/manager.php
@@ -587,26 +587,34 @@ class manager
$subscriptions = array();
+ $sql = 'SELECT method, notify, item_type
+ FROM ' . $this->user_notifications_table . '
+ WHERE user_id = ' . (int) $user_id . '
+ AND item_id = 0';
+
+ $result = $this->db->sql_query($sql);
+ $rows = array();
+
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $rows[$row['item_type']][] = $row;
+ }
+
+ $this->db->sql_freeresult($result);
+
foreach ($this->get_subscription_types() as $group_name => $types)
{
foreach ($types as $id => $type)
{
- $sql = 'SELECT method, notify
- FROM ' . $this->user_notifications_table . '
- WHERE user_id = ' . (int) $user_id . "
- AND item_type = '" . $this->db->sql_escape($id) . "'
- AND item_id = 0";
- $result = $this->db->sql_query($sql);
-
- $row = $this->db->sql_fetchrow($result);
- if (!$row)
+
+ if (empty($rows[$id]))
{
// No rows at all, default to ''
$subscriptions[$id] = array('');
}
else
{
- do
+ foreach ($rows[$id] as $row)
{
if (!$row['notify'])
{
@@ -620,10 +628,7 @@ class manager
$subscriptions[$id][] = $row['method'];
}
- while ($row = $this->db->sql_fetchrow($result));
}
-
- $this->db->sql_freeresult($result);
}
}