Skip to content

Commit 10dd818

Browse files
committed
Optimize $player->isOnline() function
1 parent 13a1598 commit 10dd818

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

system/libs/pot/OTS_Player.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class OTS_Player extends OTS_Row_DAO
108108
POT::SKILL_SHIELD => array('value' => 0, 'tries' => 0),
109109
POT::SKILL_FISH => array('value' => 0, 'tries' => 0)
110110
);
111+
112+
private static array $playersOnline;
111113
/**
112114
* Magic PHP5 method.
113115
*
@@ -765,10 +767,18 @@ public function setDeleted($deleted)
765767

766768
public function isOnline()
767769
{
768-
if($this->db->hasTable('players_online')) // tfs 1.0
769-
{
770-
$query = $this->db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $this->data['id']);
771-
return $query->rowCount() > 0;
770+
if($this->db->hasTable('players_online')) {// tfs 1.0
771+
if (!isset(self::$playersOnline)) {
772+
self::$playersOnline = [];
773+
774+
$query = $this->db->query('SELECT `player_id` FROM `players_online`');
775+
776+
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $item) {
777+
self::$playersOnline[$item['player_id']] = true;
778+
}
779+
}
780+
781+
return isset(self::$playersOnline[$this->data['id']]);
772782
}
773783

774784
if( !isset($this->data['online']) )

0 commit comments

Comments
 (0)