Skip to content

Commit 50d6a61

Browse files
committed
Fix audits prune
1 parent 4f72181 commit 50d6a61

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: run-tests
22

33
on:
44
push:
5-
branches: [master]
5+
branches: [v13]
66
pull_request:
7-
branches: [master]
7+
branches: [v13]
88

99
jobs:
1010
run-tests:

src/Drivers/Database.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,17 @@ public function prune(Auditable $model): bool
2323
{
2424
if (($threshold = $model->getAuditThreshold()) > 0) {
2525
$auditClass = get_class($model->audits()->getModel());
26-
$auditModel = new $auditClass;
26+
$keyName = (new $auditClass)->getKeyName();
27+
$forRemoval = array_slice(
28+
$model->audits()->latest()->pluck($keyName)->all(),
29+
$threshold
30+
);
2731

28-
return $model->audits()
29-
->leftJoinSub(
30-
$model->audits()->getQuery()
31-
->select($auditModel->getKeyName())->limit($threshold)->latest(),
32-
'audit_threshold',
33-
function ($join) use ($auditModel) {
34-
$join->on(
35-
$auditModel->gettable().'.'.$auditModel->getKeyName(),
36-
'=',
37-
'audit_threshold.'.$auditModel->getKeyName()
38-
);
39-
}
40-
)
41-
->whereNull('audit_threshold.'.$auditModel->getKeyName())
42-
->delete() > 0;
32+
if (count($forRemoval)) {
33+
return $model->audits()
34+
->whereIntegerInRaw($keyName, $forRemoval)
35+
->delete() > 0;
36+
}
4337
}
4438

4539
return false;

src/Resolvers/UrlResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function resolve(Auditable $auditable): string
2525
public static function resolveCommandLine(): string
2626
{
2727
$command = Request::server('argv', null);
28-
if (is_array($command)) {
28+
if (is_array($command)) { // @phpstan-ignore function.impossibleType
2929
return implode(' ', $command);
3030
}
3131

0 commit comments

Comments
 (0)