Skip to content

Commit 9f28f24

Browse files
committed
SQL query optimised
1 parent 7101759 commit 9f28f24

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

imcger/imgupload/event/main_listener.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,20 @@ public function set_template_vars()
113113
$allowed_images = [];
114114
$img_max_thumb_width = $this->config['imcger_imgupload_img_max_thumb_width'];
115115

116-
// Get image groups
117-
$sql_ary = 'SELECT group_id FROM ' . EXTENSION_GROUPS_TABLE . ' WHERE cat_id = 1';
118-
$result_group = $this->db->sql_query($sql_ary);
116+
// Get extension from image groups
117+
$sql_ary = 'SELECT e.extension
118+
FROM ' . EXTENSIONS_TABLE . ' e
119+
JOIN ' . EXTENSION_GROUPS_TABLE . ' g
120+
WHERE e.group_id = g.group_id
121+
AND g.cat_id = 1';
119122

120-
while ($group_row = $this->db->sql_fetchrow($result_group))
121-
{
122-
// Get extension from image groups
123-
$sql_ary = 'SELECT extension FROM ' . EXTENSIONS_TABLE . ' WHERE group_id = ' . (int) $group_row['group_id'];
124-
$result_ext = $this->db->sql_query($sql_ary);
123+
$result_ext = $this->db->sql_query($sql_ary);
124+
125+
$ext_ary = $this->db->sql_fetchrowset($result_ext);
126+
127+
// Convert 2 dimensional array into simple array
128+
$allowed_images = array_map(function ($n) {return $n['extension'];}, $ext_ary);
125129

126-
while ($row = $this->db->sql_fetchrow($result_ext))
127-
{
128-
$allowed_images[] = $row['extension'];
129-
}
130-
}
131130
$this->db->sql_freeresult();
132131

133132
$metadata_manager = $this->ext_manager->create_extension_metadata_manager('imcger/imgupload');

0 commit comments

Comments
 (0)