Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3619,11 +3619,13 @@ public function pruneOutdatedSyncTokens(int $keep, int $retention): int {
return 0;
}

$cutoff = max(0, time() - $retention);

$query = $this->db->getQueryBuilder();
$query->delete('calendarchanges')
->where(
$query->expr()->lte('id', $query->createNamedParameter($maxId - $keep, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT),
$query->expr()->lte('created_at', $query->createNamedParameter($retention)),
$query->expr()->lte('created_at', $query->createNamedParameter($cutoff, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT),
);
return $query->executeStatement();
}
Expand Down
4 changes: 3 additions & 1 deletion apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1496,11 +1496,13 @@ public function pruneOutdatedSyncTokens(int $keep, int $retention): int {
return 0;
}

$cutoff = max(0, time() - $retention);

$query = $this->db->getQueryBuilder();
$query->delete('addressbookchanges')
->where(
$query->expr()->lte('id', $query->createNamedParameter($maxId - $keep, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT),
$query->expr()->lte('created_at', $query->createNamedParameter($retention)),
$query->expr()->lte('created_at', $query->createNamedParameter($cutoff, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT),
);
return $query->executeStatement();
}
Expand Down
11 changes: 6 additions & 5 deletions apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1398,11 +1398,12 @@ public function testPruneOutdatedSyncTokens(): void {
EOD;
$this->backend->updateCalendarObject($calendarId, $uri, $calData);

// Keep everything
$deleted = $this->backend->pruneOutdatedSyncTokens(0, 0);
// Keep everything by using a retention duration larger than the row age
$deleted = $this->backend->pruneOutdatedSyncTokens(0, time());
self::assertSame(0, $deleted);

$deleted = $this->backend->pruneOutdatedSyncTokens(0, time());
// A retention duration of 0 means everything older than "now" is eligible
$deleted = $this->backend->pruneOutdatedSyncTokens(0, 0);
// At least one from the object creation and one from the object update
$this->assertGreaterThanOrEqual(2, $deleted);
$changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 1);
Expand Down Expand Up @@ -1468,7 +1469,7 @@ public function testPruneOutdatedSyncTokens(): void {
$this->assertEmpty($changes['deleted']);

// Delete all but last change
$deleted = $this->backend->pruneOutdatedSyncTokens(1, time());
$deleted = $this->backend->pruneOutdatedSyncTokens(1, 0);
$this->assertEquals(1, $deleted); // We had two changes before, now one

// Only update should remain
Expand All @@ -1478,7 +1479,7 @@ public function testPruneOutdatedSyncTokens(): void {
$this->assertEmpty($changes['deleted']);

// Check that no crash occurs when prune is called without current changes
$deleted = $this->backend->pruneOutdatedSyncTokens(1, time());
$deleted = $this->backend->pruneOutdatedSyncTokens(1, 0);
self::assertSame(0, $deleted);
}

Expand Down
11 changes: 6 additions & 5 deletions apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,11 +875,12 @@ public function testPruneOutdatedSyncTokens(): void {
$this->backend->createCard($addressBookId, $uri, $this->vcardTest0);
$this->backend->updateCard($addressBookId, $uri, $this->vcardTest1);

// Do not delete anything if week data as old as ts=0
$deleted = $this->backend->pruneOutdatedSyncTokens(0, 0);
// Keep everything by using a retention duration larger than the row age
$deleted = $this->backend->pruneOutdatedSyncTokens(0, time());
self::assertSame(0, $deleted);

$deleted = $this->backend->pruneOutdatedSyncTokens(0, time());
// A retention duration of 0 means everything older than "now" is eligible
$deleted = $this->backend->pruneOutdatedSyncTokens(0, 0);
// At least one from the object creation and one from the object update
$this->assertGreaterThanOrEqual(2, $deleted);
$changes = $this->backend->getChangesForAddressBook($addressBookId, $syncToken, 1);
Expand Down Expand Up @@ -911,7 +912,7 @@ public function testPruneOutdatedSyncTokens(): void {
$this->assertEmpty($changes['deleted']);

// Delete all but last change
$deleted = $this->backend->pruneOutdatedSyncTokens(1, time());
$deleted = $this->backend->pruneOutdatedSyncTokens(1, 0);
$this->assertEquals(1, $deleted); // We had two changes before, now one

// Only update should remain
Expand All @@ -921,6 +922,6 @@ public function testPruneOutdatedSyncTokens(): void {
$this->assertEmpty($changes['deleted']);

// Check that no crash occurs when prune is called without current changes
$deleted = $this->backend->pruneOutdatedSyncTokens(1, time());
$deleted = $this->backend->pruneOutdatedSyncTokens(1, 0);
}
}
Loading