Skip to content

Commit

Permalink
Fix RSI v1.0.2
Browse files Browse the repository at this point in the history
- Add constant `CACHE_KEY`
- Split Forum setting data to 50 chunk size for SQL Update

Signed-off-by: Dark❶ <25451052+Dark1z@users.noreply.github.com>
  • Loading branch information
Dark1z committed Mar 27, 2021
1 parent b958895 commit 0e4e238
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
15 changes: 11 additions & 4 deletions controller/acp_forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/**
* @ignore
*/
use dark1\reducesearchindex\core\consts;
use phpbb\language\language;
use phpbb\log\log;
use phpbb\request\request;
Expand Down Expand Up @@ -103,12 +104,18 @@ private function submit_forums()
{
// Set the options the user configured
$forum_enable = $this->request->variable('forum_enable', [0 => 0]);
foreach ($forum_enable as $forum_id => $enable)
$forum_enable = array_chunk($forum_enable, 50, true);
foreach ($forum_enable as $forums_chunk)
{
$sql = 'UPDATE ' . FORUMS_TABLE . ' SET dark1_rsi_f_enable = ' . (int) $enable . ' WHERE forum_id = ' . (int) $forum_id;
$this->db->sql_query($sql);
$this->db->sql_transaction('begin');
foreach ($forums_chunk as $forum_id => $enable)
{
$sql = 'UPDATE ' . FORUMS_TABLE . ' SET dark1_rsi_f_enable = ' . (int) $enable . ' WHERE forum_id = ' . (int) $forum_id;
$this->db->sql_query($sql);
}
$this->db->sql_transaction('commit');
}

$this->cache->destroy('_dark1_rsi_search_matrix');
$this->cache->destroy(consts::CACHE_KEY);
}
}
7 changes: 5 additions & 2 deletions core/consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class consts
* P : Time Zone [-12:00 - +14:00]
*
* Example : 1970-01-01 12:00:00 AM +00:00
*/
const TIME_FORMAT = 'Y-m-d h:i:s A P';
**/
const TIME_FORMAT = 'Y-m-d h:i:s A P';

// RSI Cache Key
const CACHE_KEY = '_dark1_rsi_search_matrix';
}
23 changes: 9 additions & 14 deletions event/main_listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ public function search_native_index_before($event)
*/
private function get_search_forum($post_id)
{
$cache_key = '_dark1_rsi_search_matrix';

// Get search matrix data from the cache
$search_matrix = $this->cache->get($cache_key);
$search_matrix = $this->cache->get(consts::CACHE_KEY);

if ($search_matrix === false || !isset($search_matrix[$post_id]))
{
Expand All @@ -155,16 +153,13 @@ private function get_search_forum($post_id)
'FROM' => [
POSTS_TABLE => 'p',
],
'LEFT_JOIN' => [
[
'FROM' => [TOPICS_TABLE => 't'],
'ON' => 't.topic_id = p.topic_id',
],
[
'FROM' => [FORUMS_TABLE => 'f'],
'ON' => 'f.forum_id = p.forum_id',
],
],
'LEFT_JOIN' => [[
'FROM' => [TOPICS_TABLE => 't'],
'ON' => 't.topic_id = p.topic_id',
], [
'FROM' => [FORUMS_TABLE => 'f'],
'ON' => 'f.forum_id = p.forum_id',
],],
'WHERE' => 'p.post_id = ' . (int) $post_id,
];
$sql = $this->db->sql_build_query('SELECT', $sql_ary);
Expand All @@ -176,7 +171,7 @@ private function get_search_forum($post_id)
$this->db->sql_freeresult($result);

// Cache post matrix data
$this->cache->put($cache_key, $search_matrix);
$this->cache->put(consts::CACHE_KEY, $search_matrix);
}

return $search_matrix[$post_id];
Expand Down

0 comments on commit 0e4e238

Please sign in to comment.