mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-30 00:43:16 +00:00
commit
6db781aa91
1 changed files with 77 additions and 47 deletions
|
@ -29,7 +29,19 @@ class AutospamUpdateCachedDataPipeline implements ShouldQueue
|
||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
|
$spamExists = Storage::exists(AutospamService::MODEL_SPAM_PATH);
|
||||||
|
if($spamExists) {
|
||||||
$spam = json_decode(Storage::get(AutospamService::MODEL_SPAM_PATH), true);
|
$spam = json_decode(Storage::get(AutospamService::MODEL_SPAM_PATH), true);
|
||||||
|
} else {
|
||||||
|
$spam = [
|
||||||
|
'documents' => [
|
||||||
|
'spam' => 0
|
||||||
|
],
|
||||||
|
'words' => [
|
||||||
|
'spam' => []
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
$newSpam = AutospamCustomTokens::whereCategory('spam')->get();
|
$newSpam = AutospamCustomTokens::whereCategory('spam')->get();
|
||||||
foreach($newSpam as $ns) {
|
foreach($newSpam as $ns) {
|
||||||
$key = strtolower($ns->token);
|
$key = strtolower($ns->token);
|
||||||
|
@ -40,11 +52,25 @@ class AutospamUpdateCachedDataPipeline implements ShouldQueue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$newSpamCount = count($spam['words']['spam']);
|
$newSpamCount = count($spam['words']['spam']);
|
||||||
|
if($newSpamCount) {
|
||||||
$spam['documents']['spam'] = $newSpamCount;
|
$spam['documents']['spam'] = $newSpamCount;
|
||||||
arsort($spam['words']['spam']);
|
arsort($spam['words']['spam']);
|
||||||
Storage::put(AutospamService::MODEL_SPAM_PATH, json_encode($spam, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));
|
Storage::put(AutospamService::MODEL_SPAM_PATH, json_encode($spam, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
$hamExists = Storage::exists(AutospamService::MODEL_HAM_PATH);
|
||||||
|
if($hamExists) {
|
||||||
$ham = json_decode(Storage::get(AutospamService::MODEL_HAM_PATH), true);
|
$ham = json_decode(Storage::get(AutospamService::MODEL_HAM_PATH), true);
|
||||||
|
} else {
|
||||||
|
$ham = [
|
||||||
|
'documents' => [
|
||||||
|
'ham' => 0
|
||||||
|
],
|
||||||
|
'words' => [
|
||||||
|
'ham' => []
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
$newHam = AutospamCustomTokens::whereCategory('ham')->get();
|
$newHam = AutospamCustomTokens::whereCategory('ham')->get();
|
||||||
foreach($newHam as $ns) {
|
foreach($newHam as $ns) {
|
||||||
$key = strtolower($ns->token);
|
$key = strtolower($ns->token);
|
||||||
|
@ -56,11 +82,13 @@ class AutospamUpdateCachedDataPipeline implements ShouldQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
$newHamCount = count($ham['words']['ham']);
|
$newHamCount = count($ham['words']['ham']);
|
||||||
|
if($newHamCount) {
|
||||||
$ham['documents']['ham'] = $newHamCount;
|
$ham['documents']['ham'] = $newHamCount;
|
||||||
arsort($ham['words']['ham']);
|
arsort($ham['words']['ham']);
|
||||||
|
|
||||||
Storage::put(AutospamService::MODEL_HAM_PATH, json_encode($ham, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));
|
Storage::put(AutospamService::MODEL_HAM_PATH, json_encode($ham, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($newSpamCount && $newHamCount) {
|
||||||
$combined = [
|
$combined = [
|
||||||
'documents' => [
|
'documents' => [
|
||||||
'spam' => $newSpamCount,
|
'spam' => $newSpamCount,
|
||||||
|
@ -73,6 +101,8 @@ class AutospamUpdateCachedDataPipeline implements ShouldQueue
|
||||||
];
|
];
|
||||||
|
|
||||||
Storage::put(AutospamService::MODEL_FILE_PATH, json_encode($combined, JSON_PRETTY_PRINT,JSON_UNESCAPED_SLASHES));
|
Storage::put(AutospamService::MODEL_FILE_PATH, json_encode($combined, JSON_PRETTY_PRINT,JSON_UNESCAPED_SLASHES));
|
||||||
|
}
|
||||||
|
|
||||||
Cache::forget(AutospamService::MODEL_CACHE_KEY);
|
Cache::forget(AutospamService::MODEL_CACHE_KEY);
|
||||||
Cache::forget(AutospamService::CHCKD_CACHE_KEY);
|
Cache::forget(AutospamService::CHCKD_CACHE_KEY);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue