fix: set cache expiration to next note publish to show note on publication date

fix episode, podcast and persons forms + episode scheduling
This commit is contained in:
Yassine Doghri 2021-05-25 18:00:09 +00:00
commit 0a66de3e6c
No known key found for this signature in database
GPG key ID: 3E7F89498B960C9F
14 changed files with 117 additions and 44 deletions

View file

@ -138,13 +138,35 @@ class NoteModel extends UuidModel
->orderBy('published_at', 'DESC')
->findAll();
$secondsToNextUnpublishedNote = $this->getSecondsToNextUnpublishedNote($actorId,);
cache()
->save($cacheName, $found, DECADE);
->save($cacheName, $found, $secondsToNextUnpublishedNote ? $secondsToNextUnpublishedNote : DECADE,);
}
return $found;
}
/**
* Returns the timestamp difference in seconds between the next note to publish and the current timestamp. Returns
* false if there's no note to publish
*/
public function getSecondsToNextUnpublishedNote(int $actorId): int | false
{
$result = $this->select('TIMESTAMPDIFF(SECOND, NOW(), `published_at`) as timestamp_diff',)
->where([
'actor_id' => $actorId,
])
->where('`published_at` > NOW()', null, false)
->orderBy('published_at', 'asc')
->get()
->getResultArray();
return count($result) !== 0
? (int) $result[0]['timestamp_diff']
: false;
}
/**
* Retrieves all published replies for a given note. By default, it does not get replies from blocked actors.
*