diff --git a/CHANGELOG.md b/CHANGELOG.md
index 046a5d6d3..e7a1a062b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@
- Some improvements for integrity checker [\#1501](https://github.com/torrentpier/torrentpier/pull/1501) ([belomaxorka](https://github.com/belomaxorka))
- Hide in topic: Added country hiding [\#1535](https://github.com/torrentpier/torrentpier/pull/1535) ([belomaxorka](https://github.com/belomaxorka))
- Hide vote button in topic for guests [\#1507](https://github.com/torrentpier/torrentpier/pull/1507) ([belomaxorka](https://github.com/belomaxorka))
+- Word censor code optimization [\#1537](https://github.com/torrentpier/torrentpier/pull/1537) ([belomaxorka](https://github.com/belomaxorka))
- Minor improvements [\#1502](https://github.com/torrentpier/torrentpier/pull/1502), [\#1506](https://github.com/torrentpier/torrentpier/pull/1506), [\#1509](https://github.com/torrentpier/torrentpier/pull/1509), [\#1511](https://github.com/torrentpier/torrentpier/pull/1511), [\#1515](https://github.com/torrentpier/torrentpier/pull/1515), [\#1516](https://github.com/torrentpier/torrentpier/pull/1516), [\#1517](https://github.com/torrentpier/torrentpier/pull/1517), [\#1519](https://github.com/torrentpier/torrentpier/pull/1519), [\#1523](https://github.com/torrentpier/torrentpier/pull/1523), [\#1525](https://github.com/torrentpier/torrentpier/pull/1525), [\#1530](https://github.com/torrentpier/torrentpier/pull/1530), [\#1532](https://github.com/torrentpier/torrentpier/pull/1532), [\#1536](https://github.com/torrentpier/torrentpier/pull/1536) ([belomaxorka](https://github.com/belomaxorka))
- New Crowdin updates [\#1504](https://github.com/torrentpier/torrentpier/pull/1504), [\#1513](https://github.com/torrentpier/torrentpier/pull/1513) ([Exileum](https://github.com/Exileum))
diff --git a/admin/admin_words.php b/admin/admin_words.php
index 827af160e..65c3d05c4 100644
--- a/admin/admin_words.php
+++ b/admin/admin_words.php
@@ -80,7 +80,7 @@ if ($mode != '') {
bb_die('Could not insert data into words table');
}
- CACHE('bb_cache')->rm('censored');
+ $datastore->update('censor');
$message .= '
' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', '') . '
' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '');
bb_die($message);
@@ -94,7 +94,7 @@ if ($mode != '') {
bb_die('Could not remove data from words table');
}
- CACHE('bb_cache')->rm('censored');
+ $datastore->update('censor');
bb_die($lang['WORD_REMOVED'] . '
' . sprintf($lang['CLICK_RETURN_WORDADMIN'], '', '') . '
' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''));
} else {
diff --git a/library/includes/datastore/build_censor.php b/library/includes/datastore/build_censor.php
new file mode 100644
index 000000000..87c9aba27
--- /dev/null
+++ b/library/includes/datastore/build_censor.php
@@ -0,0 +1,21 @@
+fetch_rowset($sql) as $row) {
+ $words[$row['word_id']] = $row;
+}
+
+$this->store('censor', $words);
diff --git a/src/Censor.php b/src/Censor.php
index 39137c8a2..676efcfd9 100644
--- a/src/Censor.php
+++ b/src/Censor.php
@@ -34,18 +34,23 @@ class Censor
*/
public function __construct()
{
- global $bb_cfg;
+ global $bb_cfg, $datastore;
if (!$bb_cfg['use_word_censor']) {
return;
}
- if (!$words = CACHE('bb_cache')->get('censored')) {
- $words = DB()->fetch_rowset("SELECT word, replacement FROM " . BB_WORDS);
- CACHE('bb_cache')->set('censored', $words, 7200);
+ // Get censored words
+ if (!$censoredWords = $datastore->get('censor')) {
+ $datastore->update('censor');
+ $censoredWords = $datastore->get('censor');
}
- foreach ($words as $word) {
+ if (isset($censoredWords['no_words'])) {
+ return;
+ }
+
+ foreach ($censoredWords as $word) {
$this->words[] = '#(?replacements[] = $word['replacement'];
}
diff --git a/src/Legacy/Datastore/Common.php b/src/Legacy/Datastore/Common.php
index d125575bd..3ee9a4216 100644
--- a/src/Legacy/Datastore/Common.php
+++ b/src/Legacy/Datastore/Common.php
@@ -39,6 +39,7 @@ class Common
*/
public array $known_items = [
'cat_forums' => 'build_cat_forums.php',
+ 'censor' => 'build_censor.php',
'check_updates' => 'build_check_updates.php',
'files_integrity' => 'build_files_integrity.php',
'jumpbox' => 'build_cat_forums.php',