-
Notifications
You must be signed in to change notification settings - Fork 398
[v14] Phpstan fixes #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v14] Phpstan fixes #1021
Conversation
|
True, you would have to edit the ID column of the audits table to actually make that a problem though. Depends how much of a risk you think that is, that someone would both enable pruning AND change the type of the ID column. |
would something like this work? ->whereRaw($keyName ." IN ('".implode("', '", $forRemoval)."')") I think in MariaDb, it would cover int and string, but I don't know about other DB managers |
yeah, it can't run out of placeholders if there aren't any 👌 |
I see that the same thing is used in all the grammars, but the question was if the field is int, when making it a string |
Making some comparisons it seems to me that the current Also #1019 (comment)
In case it is used again in the future, the code that was there is: public function prune(Auditable $model): bool
{
if (($threshold = $model->getAuditThreshold()) > 0) {
$auditClass = get_class($model->audits()->getModel());
$keyName = (new $auditClass)->getKeyName();
$forRemoval = array_slice(
$model->audits()->latest()->pluck($keyName)->all(),
$threshold
);
if (count($forRemoval)) {
if (is_string($forRemoval[0])) {
$forRemoval = "'" . implode("', '", $forRemoval) . "'";
} else {
$forRemoval = implode(', ', $forRemoval);
}
return $model->audits()
->whereRaw($keyName ." in ($forRemoval)")
->delete() > 0;
}
}
return false;
} |
https://github.com/owen-it/laravel-auditing/pull/933/files
In the old version (
->get()->slice($threshold)->pluck('id')
) Memory performance was failing, since withget()
all the data was brought as eloquent modelsNow (
->pluck($keyName)->all()
)pluck/all
is done directly, which would only use an int arraywhereIn
was replaced bywhereIntegerInRaw
(avoid too many Placeholders issue)The same solution works on older Laravel versions, if merged it would also be released in v13: https://github.com/owen-it/laravel-auditing/actions/runs/14862464393/job/41730649233
UPDATE:
whereIntegerInRaw
would cause problems when the key is a string, like UUID?