directus / directus/directus

To handle 3 Million records in session table

Open
#19,718 1 comment 0 reactions 0 assignees View on GitHub
Auth Engine Optimization
Dominant language
TypeScript
Stars
37.9k
Forks
4.9k
Avg merge
3d 21h
Merged PRs (30d)
36

Description

### Describe the Improvement

We set 7d token expiry, and the session table generated 3 Million records in 3 days. It makes the database slow, timeout in the frontend application, and the site is unavailable during peak.

We suspect the slowness may be caused by the code trying to delete an expired token in the table during the auth login call, in line 220 in the authentication.ts.

await this.knex('directus_sessions').delete().where('expires', '<', new Date());

It could be better if we move above to a cronjob or create a database index for "expires" field.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.