refactor: counting users on homepage uses indexes

... and some intelligent queries for a change :P
This commit is contained in:
Martin Ambrus
2017-10-22 21:44:33 +02:00
parent 1749ff0c1d
commit 71ad4307e1
4 changed files with 14 additions and 6 deletions
+5 -5
View File
@@ -124,8 +124,8 @@ include ("GameEngine/Lang/".LANG.".php");
<td><?php
$return=mysqli_query($link,"SELECT * FROM " . TB_PREFIX . "users WHERE tribe!=0 AND tribe!=4 AND tribe!=5");
$users=(!empty($return))? mysqli_num_rows($return):0;
$return=mysqli_query($link,"SELECT Count(*) as Total FROM " . TB_PREFIX . "users WHERE tribe!=0 AND tribe!=4 AND tribe!=5");
$users=(!empty($return))? mysqli_fetch_assoc($return)['Total']:0;
echo $users;
?></td>
</tr>
@@ -139,8 +139,8 @@ include ("GameEngine/Lang/".LANG.".php");
<td><?php
$return = mysqli_query($link,"SELECT * FROM " . TB_PREFIX . "users WHERE " . time() . "-timestamp < (3600*24) AND tribe!=0 AND tribe!=4 AND tribe!=5");
$active=(!empty($return))? mysqli_num_rows($return):0;
$return = mysqli_query($link,"SELECT Count(*) as Total FROM " . TB_PREFIX . "users WHERE timestamp > ".(time() - (3600*24))." AND tribe!=0 AND tribe!=4 AND tribe!=5");
$active=(!empty($return))? mysqli_fetch_assoc($return)['Total']:0;
echo $active;
?></td>
@@ -155,7 +155,7 @@ include ("GameEngine/Lang/".LANG.".php");
<td><?php
$return = mysqli_query($link,"SELECT * FROM " . TB_PREFIX . "users WHERE " . time() . "-timestamp < (60*10) AND tribe!=0 AND tribe!=4 AND tribe!=5");
$return = mysqli_query($link,"SELECT Count(*) FROM " . TB_PREFIX . "users WHERE timestamp > ".(time() - (60*10))." AND tribe!=0 AND tribe!=4 AND tribe!=5");
$online=(!empty($return))? mysqli_num_rows($return):0;
echo $online;
+4 -1
View File
@@ -1548,7 +1548,10 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%users` (
KEY `invited` (`invited`),
KEY `lastupdate` (`lastupdate`),
KEY `alliance` (`alliance`),
KEY `username` (`username`(25)) USING BTREE
KEY `username` (`username`(25)) USING BTREE,
KEY `tribe` (`tribe`),
KEY `timestamp` (`timestamp`),
KEY `timestamp-tribe` (`timestamp`,`tribe`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
--
+4
View File
@@ -1,3 +1,7 @@
-- 22.10.2017 -> SQL optimizations
ALTER TABLE `s1_users` ADD INDEX(`tribe`);
ALTER TABLE `s1_users` ADD INDEX `timestamp-tribe` (`timestamp`, `tribe`);
-- 22.10.2017 -> forum topics table and indexe changes
ALTER TABLE `s1_forum_post` CHANGE `topic` `topic` INT NULL DEFAULT NULL;
ALTER TABLE `s1_forum_post` CHANGE `owner` `owner` INT NULL DEFAULT NULL;
+1
View File
@@ -1,4 +1,5 @@
- add checkbox when sending units for a raid to include the attack in the raid list, if eligible
- change "incoming attacker" title of the raid list icon when actually attacking a farm (it should be "Own attacking troops")
- normalize forum tables - varchar is used for numeric values and is joined with int field
- finish parts in Admin that are unfinished (mostly delete -X- buttons and Alliance settings)
- add batching logic to mehods which get called too frequently and multiple times (example - Message::sendMessage() now that is sends messages for each forum post)