mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-12 03:06:43 +02:00
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:
parent
e65e236bbc
commit
9303e51bc5
16 changed files with 348 additions and 85 deletions
|
|
@ -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>>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue