Skip to content

Commit ca60436

Browse files
committed
chore: bring files from branch to latest versions of main branch
Signed-off-by: Jonas <[email protected]>
1 parent 0b6e312 commit ca60436

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/Db/SessionMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ public function deleteOldSessions(int $ageInSeconds): int {
178178
return $deletedCount;
179179
}
180180

181-
public function deleteOrphanedSteps(): int {
181+
public function deleteOrphanedSteps(int $ageInSeconds): int {
182182
$startTime = microtime(true);
183183
$maxExecutionSeconds = 30;
184184
$batchSize = 1000;
185185
$deletedCount = 0;
186-
$safetyBufferTime = time() - 86400;
186+
$ageThreshold = time() - $ageInSeconds;
187187

188188
do {
189189
$orphanedStepsQb = $this->db->getQueryBuilder();
@@ -192,7 +192,7 @@ public function deleteOrphanedSteps(): int {
192192
->leftJoin('st', 'text_sessions', 's', $orphanedStepsQb->expr()->eq('st.document_id', 's.document_id'))
193193
->leftJoin('st', 'text_documents', 'd', $orphanedStepsQb->expr()->eq('st.document_id', 'd.id'))
194194
->where($orphanedStepsQb->expr()->isNull('s.id'))
195-
->andWhere($orphanedStepsQb->expr()->lt('st.timestamp', $orphanedStepsQb->createNamedParameter($safetyBufferTime)))
195+
->andWhere($orphanedStepsQb->expr()->lt('st.timestamp', $orphanedStepsQb->createNamedParameter($ageThreshold)))
196196
->andWhere(
197197
$orphanedStepsQb->expr()->orX(
198198
$orphanedStepsQb->expr()->isNull('d.id'),

tests/unit/Db/SessionMapperTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testDeleteOrphanedSteps() {
142142
$this->sessionMapper->clearAll();
143143
$this->stepMapper->clearAll();
144144

145-
$oldTimestamp = time() - 86401;
145+
$eightDaysAgo = time() - (8 * 24 * 60 * 60);
146146

147147
// Create document
148148
$document = $this->documentMapper->insert(Document::fromParams([
@@ -166,7 +166,7 @@ public function testDeleteOrphanedSteps() {
166166
'sessionId' => 99999,
167167
'documentId' => $document->getId(),
168168
'data' => 'ORPHANED_OLD_VERSION',
169-
'timestamp' => $oldTimestamp,
169+
'timestamp' => $eightDaysAgo,
170170
'version' => 1
171171
]));
172172

@@ -185,16 +185,17 @@ public function testDeleteOrphanedSteps() {
185185
'sessionId' => 99999,
186186
'documentId' => $document->getId(),
187187
'data' => 'ORPHANED_NEW_VERSION',
188-
'timestamp' => $oldTimestamp,
188+
'timestamp' => $eightDaysAgo,
189189
'version' => 3
190190
]));
191191

192192
// Verify steps for document 1 and 99999
193193
self::assertCount(3, $this->stepMapper->find(1, 0));
194194
self::assertCount(1, $this->stepMapper->find(99999, 0));
195195

196-
// Verify orphan delete
197-
$deletedCount = $this->sessionMapper->deleteOrphanedSteps();
196+
// Delete orphaned steps older than 7 days
197+
$sevenDays = 7 * 24 * 60 * 60;
198+
$deletedCount = $this->sessionMapper->deleteOrphanedSteps($sevenDays);
198199
self::assertEquals(2, $deletedCount);
199200
}
200201
}

0 commit comments

Comments
 (0)