mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 08:44:49 +00:00
commit
6db781aa91
1 changed files with 77 additions and 47 deletions
|
@ -24,56 +24,86 @@ class AutospamUpdateCachedDataPipeline implements ShouldQueue
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
$spam = json_decode(Storage::get(AutospamService::MODEL_SPAM_PATH), true);
|
$spamExists = Storage::exists(AutospamService::MODEL_SPAM_PATH);
|
||||||
$newSpam = AutospamCustomTokens::whereCategory('spam')->get();
|
if($spamExists) {
|
||||||
foreach($newSpam as $ns) {
|
$spam = json_decode(Storage::get(AutospamService::MODEL_SPAM_PATH), true);
|
||||||
$key = strtolower($ns->token);
|
} else {
|
||||||
if(isset($spam['words']['spam'][$key])) {
|
$spam = [
|
||||||
$spam['words']['spam'][$key] = $spam['words']['spam'][$key] + $ns->weight;
|
'documents' => [
|
||||||
} else {
|
'spam' => 0
|
||||||
$spam['words']['spam'][$key] = $ns->weight;
|
],
|
||||||
}
|
'words' => [
|
||||||
}
|
'spam' => []
|
||||||
$newSpamCount = count($spam['words']['spam']);
|
]
|
||||||
$spam['documents']['spam'] = $newSpamCount;
|
];
|
||||||
arsort($spam['words']['spam']);
|
}
|
||||||
Storage::put(AutospamService::MODEL_SPAM_PATH, json_encode($spam, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));
|
$newSpam = AutospamCustomTokens::whereCategory('spam')->get();
|
||||||
|
foreach($newSpam as $ns) {
|
||||||
|
$key = strtolower($ns->token);
|
||||||
|
if(isset($spam['words']['spam'][$key])) {
|
||||||
|
$spam['words']['spam'][$key] = $spam['words']['spam'][$key] + $ns->weight;
|
||||||
|
} else {
|
||||||
|
$spam['words']['spam'][$key] = $ns->weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$newSpamCount = count($spam['words']['spam']);
|
||||||
|
if($newSpamCount) {
|
||||||
|
$spam['documents']['spam'] = $newSpamCount;
|
||||||
|
arsort($spam['words']['spam']);
|
||||||
|
Storage::put(AutospamService::MODEL_SPAM_PATH, json_encode($spam, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
$ham = json_decode(Storage::get(AutospamService::MODEL_HAM_PATH), true);
|
$hamExists = Storage::exists(AutospamService::MODEL_HAM_PATH);
|
||||||
$newHam = AutospamCustomTokens::whereCategory('ham')->get();
|
if($hamExists) {
|
||||||
foreach($newHam as $ns) {
|
$ham = json_decode(Storage::get(AutospamService::MODEL_HAM_PATH), true);
|
||||||
$key = strtolower($ns->token);
|
} else {
|
||||||
if(isset($spam['words']['ham'][$key])) {
|
$ham = [
|
||||||
$ham['words']['ham'][$key] = $ham['words']['ham'][$key] + $ns->weight;
|
'documents' => [
|
||||||
} else {
|
'ham' => 0
|
||||||
$ham['words']['ham'][$key] = $ns->weight;
|
],
|
||||||
}
|
'words' => [
|
||||||
}
|
'ham' => []
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$newHam = AutospamCustomTokens::whereCategory('ham')->get();
|
||||||
|
foreach($newHam as $ns) {
|
||||||
|
$key = strtolower($ns->token);
|
||||||
|
if(isset($spam['words']['ham'][$key])) {
|
||||||
|
$ham['words']['ham'][$key] = $ham['words']['ham'][$key] + $ns->weight;
|
||||||
|
} else {
|
||||||
|
$ham['words']['ham'][$key] = $ns->weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$newHamCount = count($ham['words']['ham']);
|
$newHamCount = count($ham['words']['ham']);
|
||||||
$ham['documents']['ham'] = $newHamCount;
|
if($newHamCount) {
|
||||||
arsort($ham['words']['ham']);
|
$ham['documents']['ham'] = $newHamCount;
|
||||||
|
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 = [
|
||||||
|
'documents' => [
|
||||||
|
'spam' => $newSpamCount,
|
||||||
|
'ham' => $newHamCount,
|
||||||
|
],
|
||||||
|
'words' => [
|
||||||
|
'spam' => $spam['words']['spam'],
|
||||||
|
'ham' => $ham['words']['ham']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
$combined = [
|
Storage::put(AutospamService::MODEL_FILE_PATH, json_encode($combined, JSON_PRETTY_PRINT,JSON_UNESCAPED_SLASHES));
|
||||||
'documents' => [
|
}
|
||||||
'spam' => $newSpamCount,
|
|
||||||
'ham' => $newHamCount,
|
|
||||||
],
|
|
||||||
'words' => [
|
|
||||||
'spam' => $spam['words']['spam'],
|
|
||||||
'ham' => $ham['words']['ham']
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
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