Skip to content

Commit

Permalink
enh: add clean up buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Aug 9, 2023
1 parent 7af30fc commit 18fb955
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apps/files_reminders/lib/Db/ReminderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OCA\FilesReminders\Db;

use DateTime;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -138,12 +139,13 @@ public function findOverdue() {
/**
* @return Reminder[]
*/
public function findNotified(?int $limit = null) {
public function findNotified(DateTime $buffer, ?int $limit = null) {
$qb = $this->db->getQueryBuilder();

$qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
->from($this->getTableName())
->where($qb->expr()->eq('notified', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)))
->andWhere($qb->expr()->lt('due_date', $qb->createNamedParameter($buffer, IQueryBuilder::PARAM_DATE)))
->orderBy('due_date', 'ASC')
->setMaxResults($limit);

Expand Down
5 changes: 4 additions & 1 deletion apps/files_reminders/lib/Service/ReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ public function send(Reminder $reminder): void {
}

public function cleanUp(?int $limit = null): void {
$reminders = $this->reminderMapper->findNotified($limit);
$buffer = (new DateTime())
->setTimezone(new DateTimeZone('UTC'))
->modify('-1 day');
$reminders = $this->reminderMapper->findNotified($buffer, $limit);
foreach ($reminders as $reminder) {
$this->reminderMapper->delete($reminder);
}
Expand Down

0 comments on commit 18fb955

Please sign in to comment.