Skip to content

Commit fd284ef

Browse files
authored
Merge pull request #1002 from SmoKE585/alpha
Уменьшено в 20 раз количество запросов к БД
2 parents 2177b60 + 525a58a commit fd284ef

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

modules/panel.class.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class panel extends module
1111
{
1212

1313
var $action;
14+
var $print;
15+
var $ajax;
1416

1517
// --------------------------------------------------------------------
1618
function __construct()
@@ -126,7 +128,7 @@ function run()
126128
include_once(DIR_MODULES . 'inc_panel_ajax.php');
127129
}
128130

129-
if ($this->print || $_GET['print']) {
131+
if ($this->print || (isset($_GET['print']) && $_GET['print'])) {
130132
$this->print = 1;
131133
$out['PRINT'] = 1;
132134
}
@@ -156,7 +158,9 @@ function run()
156158
$modules = SQLSelect($sqlQuery);
157159
$old_cat = 'some_never_should_be_category_name';
158160
$modulesCnt = count($modules);
159-
161+
162+
$getNOTY = SQLSelect("select pln.*, pl.MODULE_NAME from plugins_noty pln join plugins pl on pln.PLUGINS_ID=pl.id WHERE pln.READ = '0'");
163+
160164
for ($i = 0; $i < $modulesCnt; $i++) {
161165
if ($modules[$i]['NAME'] == $this->action) {
162166
$modules[$i]['SELECTED'] = 1;
@@ -177,29 +181,29 @@ function run()
177181
$last_allow = $i;
178182
}
179183

180-
if(preg_match('|<#(.*?)#>|si', $modules[$i]['TITLE'], $arr)) {
181-
$titleSearchNoty = constant($arr[1]);
182-
} else {
183-
$titleSearchNoty = $modules[$i]['NAME'];
184-
}
185-
186-
$getNOTY = SQLSelect("SELECT * FROM `plugins_noty` WHERE `PLUGINS_ID` = (SELECT ID FROM `plugins` WHERE `MODULE_NAME` = '".$titleSearchNoty."') AND `READ` = 0 ORDER BY `ADD` DESC LIMIT 10");
184+
foreach($getNOTY as $keyNoty => $notyValue) {
185+
if($notyValue['MODULE_NAME'] == $modules[$i]["NAME"]) {
187186

188-
if(!empty($getNOTY)) {
189-
$modules[$i]['PLUGINS_NOTY_COUNT'] = count($getNOTY);
190-
$modules[$i]['PLUGINS_NOTY_COLOR'] = $getNOTY[0]['TYPE'];
191-
$modules[$i]['PLUGINS_ID'] = $getNOTY[0]['PLUGINS_ID'];
187+
if(preg_match('|<#(.*?)#>|si', $notyValue['MODULE_NAME'], $arr)) {
188+
$titleSearchNoty = constant($arr[1]);
189+
} else {
190+
$titleSearchNoty = $notyValue['MODULE_NAME'];
191+
}
192192

193-
foreach($getNOTY as $keyNoty => $noty) {
194-
$getNOTY[$keyNoty]['ADD_HUMAN'] = date('d.m.Y H:i', $noty['ADD']);
193+
$modules[$i]['PLUGINS_NOTY_COUNT'] = $modules[$i]['PLUGINS_NOTY_COUNT']+1;
194+
$modules[$i]['PLUGINS_NOTY_COLOR'] = $notyValue['TYPE'];
195+
$modules[$i]['PLUGINS_ID'] = $notyValue['PLUGINS_ID'];
196+
197+
$getNOTY[$keyNoty]['ADD_HUMAN'] = date('d.m.Y H:i', $notyValue['ADD']);
198+
199+
$modules[$i]['PLUGINS_NOTY'][] = $getNOTY[$keyNoty];
200+
201+
unset($getNOTY[$keyNoty]);
202+
} else {
203+
$modules[$i]['PLUGINS_ID'] = $notyValue['PLUGINS_ID'] ?? null;
195204
}
196-
197-
$modules[$i]['PLUGINS_NOTY'] = $getNOTY;
198-
} else {
199-
$modules[$i]['PLUGINS_NOTY_COUNT'] = 0;
200-
$modules[$i]['PLUGINS_ID'] = $getNOTY[0]['PLUGINS_ID'];
201205
}
202-
206+
203207
if (file_exists(ROOT . 'img/modules/' . $modules[$i]['NAME'] . '.png')) {
204208
$modules[$i]['ICON_SM'] = ROOTHTML . 'img/modules/' . $modules[$i]['NAME'] . '.png';
205209
} else {

0 commit comments

Comments
 (0)