From: Matteo Nastasi Date: Thu, 16 Apr 2020 16:15:30 +0000 (+0200) Subject: add table cache for table_content method X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=511cb55dd8fe435034e2d3dc667a54ccdbf9ee52;p=brisk.git add table cache for table_content method --- diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index affe74a..7f5d437 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -657,6 +657,8 @@ class Table { var $wakeup_time; + var $cache; + function Table() { } @@ -688,6 +690,8 @@ class Table { $thiz->wakeup_time = 0; + $thiz->cache = NULL; + return ($thiz); } @@ -711,6 +715,8 @@ class Table { $this->table_start = $from->table_start; $this->wakeup_time = $from->wakeup_time; + + $this->cache = $from->cache; } function myclone($from) @@ -745,6 +751,8 @@ class Table { $thiz->wakeup_time = $from->wakeup_time; + $thiz->cache = $from->cache; + return ($thiz); } @@ -1454,7 +1462,7 @@ class Brisk for ($i = 0 ; $i < TABLES_N ; $i++) { - $ret .= $this->table_content($user, $i); + $ret .= $this->table_content($user, $i, TRUE); $ret .= $this->table[$i]->act_content($user); if ($this->table[$i]->wag_own != -1) @@ -2712,7 +2720,7 @@ class Brisk return ($content); } - function table_content($user, $table_idx) + function table_content($user, $table_idx, $use_cache=FALSE) { $content = ""; $ret = ""; @@ -2724,10 +2732,25 @@ class Brisk $sess = $user->sess; $table = $this->table[$table_idx]; + $user_at_table = FALSE; + if ($user->stat != 'room') return; $user_cur_id = $user->idx_get(); + + # check if user at table + for ($i = 0 ; $i < $table->player_n ; $i++) { + if ($user_cur_id == $table->player[$i]) { + $user_at_table = TRUE; + break; + } + } + + if ($use_cache && !$user_at_table && $table->cache != NULL) { + return $table->cache; + } + $content = "[ "; for ($i = 0 ; $i < $table->player_n ; $i++) { $user_cur = $this->user[$table->player[$i]]; @@ -2750,7 +2773,9 @@ class Brisk $content .= ' ]'; $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content); - + if (! $user_at_table) { + $table->cache = $ret; + } return ($ret); }