delight-im / delight-im/PHP-Auth
Randomly perform garbage collection on database tables
- Dominant language
- PHP
- Stars
- 1.2k
- Forks
- 236
- PR merge metrics
- No merged PRs in 30d
Description
The following three database tables need garbage collection, clearing any rows that have been marked as expired:
```
users_remembered
users_resets
users_throttling
```
For most use cases, the best solution may be to trigger the garbage collection for a table *randomly*, e.g. during related operations, using an implementation like this:
```php
function random_float($min = null, $max = null) {
$min = isset($min) && \is_numeric($min) ? (float) $min : 0;
$max = isset($max) && \is_numeric($max) ? (float) $max : 1;
return $min + \mt_rand(0, \mt_getrandmax()) / \mt_getrandmax() * ($max - $min);
}
$probability = 0.02;
if (\random_float() < $probability) {
// perform garbage collection ...
}
```
For the `users_confirmations` table, garbage collection would be more complex. For each `user_id` and for each `email` in that table, the row with the largest `id` must be preserved so as not to break the re-sending of previous confirmations.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the code that creates and reads the users_remembered, users_resets, users_throttling, and users_confirmations tables. Review how expired rows are represented and how confirmation rows are selected; done means expired rows are periodically removed while preserving the newest row for each user_id and email in users_confirmations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- authentication, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100