bedezign / yii2-audit

Yii2 Audit records and displays web/cli requests, database changes, php/js errors and associated data.
https://bedezign.github.io/yii2-audit/
Other
193 stars 112 forks source link

lack of indexes for db table #249

Closed IlmLV closed 6 years ago

IlmLV commented 6 years ago

audit/cleanup takes hours to remove old records, should add indexes to audit_data db table, or consider partitioning this table to allow partition truncate

Blizzke commented 6 years ago

We are aware of this. The cleanup command does its magic by using the records' timestamp. . For normal operation, an index on this field would add no value whatsoever, so we opted to not add one as keep writes to that table as fast as possible (its written to every request and every added index will slow this down). So adding an index will probably not happen unless you do it on your own table, which would probably solve your issue locally.

Project wise, ideally the cleanup command should be reworked to allow specifying the last ID to keep (and get rid of everything lower). Alternatively (if we want to keep using timestamps), another table should be built that keeps track of timestamps and related IDs (like 2018-07-24 starts on ID 1234). That way internally we can still get rid of everything where id < X.

Unfortunately I have little development time to spare due to personal reasons for this project, so feel free to create a PR.