feat: add task to housekeeping setting for resetting all instance counts

set two toggle switches to run housekeeping tasks seperately if needed
This commit is contained in:
Yassine Doghri 2022-01-14 17:42:55 +00:00
commit 9303e51bc5
16 changed files with 348 additions and 85 deletions

View file

@ -149,7 +149,10 @@ class EpisodeCommentModel extends UuidModel
->whereIn('in_reply_to_id', function (BaseBuilder $builder) use (&$episodeId): BaseBuilder {
return $builder->select('id')
->from(config('Fediverse')->tablesPrefix . 'posts')
->where('episode_id', $episodeId);
->where([
'episode_id' => $episodeId,
'in_reply_to_id' => null,
]);
})
->where('`created_at` <= NOW()', null, false)
->getCompiledSelect();
@ -179,6 +182,37 @@ class EpisodeCommentModel extends UuidModel
->findAll();
}
public function resetLikesCount(): int | false
{
$commentsLikesCount = $this->db->table('likes')
->select('comment_id as id, COUNT(*) as `likes_count`')
->groupBy('id')
->get()
->getResultArray();
if ($commentsLikesCount !== []) {
$this->uuidUseBytes = false;
return $this->updateBatch($commentsLikesCount, 'id');
}
return 0;
}
public function resetRepliesCount(): int | false
{
$commentsRepliesCount = $this->select('episode_comments.id, COUNT(*) as `replies_count`')
->join('episode_comments as c2', 'episode_comments.id = c2.in_reply_to_id')
->groupBy('episode_comments.id')
->get()
->getResultArray();
if ($commentsRepliesCount !== []) {
$this->uuidUseBytes = false;
return $this->updateBatch($commentsRepliesCount, 'id');
}
return 0;
}
/**
* @param array<string, array<string|int, mixed>> $data
* @return array<string, array<string|int, mixed>>