-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Server: Resolves #9931: Add task to delete events older than a week #11372
base: dev
Are you sure you want to change the base?
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
0ada87b
to
1d3dfca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this. I think there's two issues:
- The TTL should be configurable via an env variable
- What's the impact of deleting old events - what service or function could be affected by it?
@@ -4,6 +4,8 @@ import BaseModel, { UuidType } from './BaseModel'; | |||
|
|||
export default class EventModel extends BaseModel<Event> { | |||
|
|||
private eventTtl_: number = 7 * 24 * 60 * 60 * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7 * Day
is clearer (import the Day constant)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using TokenModel as a reference that has the exact same line. I changed it there as well.
Hi Laurent, thanks for the review.
What would we gain from this? The If we need to implement it, do you have a preferred approach? I see the
I don't know, sorry. It is the approach you suggested here however: #9931 (comment) |
For audit purposes for example.
If you can check please post here |
I analyzed events and their usages, I found that we're creating events in TaskService's runTask just before and after the task is handled:
and
In
This function, in turn, is used in the Those were the only usages I could find, so they're here for auditing/debugging purposes, they have no impact on the behaviour of the application. |
I added two environment variables to enable the deletion and control the cut off period, and improved the test coverage. Hopefully that should do it :) |
a796af6
to
c32076b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking into this and for adding the two env variables and test.
For now please set it to disabled by default and default duration to 30 days. This is because even though today we don't need to keep them for a long time, in the future there could be a service that needs them for a longer time, and users who will have it configured to 7 days might have issues.
What's the meaning of setting EVENTS_AUTO_DELETE_AFTER_DAYS to 0? It deletes everything immediately?
private readonly eventTtl_: number; | ||
private readonly eventAutoDelete_: boolean; | ||
|
||
public constructor(db: DbConnection, dbSlave: DbConnection, modelFactory: NewModelFactoryHandler, config: Config) { | ||
super(db, dbSlave, modelFactory, config); | ||
this.eventAutoDelete_ = config.EVENTS_AUTO_DELETE_ENABLED; | ||
this.eventTtl_ = config.EVENTS_AUTO_DELETE_AFTER_DAYS * Day; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the config is available from TaskService, so could you please do the following:
- Remove the eventTtl_ and eventAutoDelete_ from here
- Make deleteOldEvents take the TTL as argument
- In TaskService, only enable the task if EVENTS_AUTO_DELETE_ENABLED is true (same as USER_DATA_AUTO_DELETE_ENABLED)
- Still from TaskService pass EVENTS_AUTO_DELETE_AFTER_DAYS * Day as argument
This is to make the way it works more explicit and to avoid having to modify a global object (the config) in tests, which can have unexpected results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In TaskService, only enable the task if EVENTS_AUTO_DELETE_ENABLED is true (same as USER_DATA_AUTO_DELETE_ENABLED)
That was already the case.
I made the changes you requested but had to remove a few tests that no longer made sense.
import { Day } from '../utils/time'; | ||
|
||
export default class TokenModel extends BaseModel<Token> { | ||
|
||
private tokenTtl_: number = 7 * 24 * 60 * 60 * 1000; | ||
private tokenTtl_: number = 7 * Day; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this - I agree it's ok as a change but I prefer to keep commits focused on one specific issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
return this.withTransaction(async () => { | ||
await this.db(this.tableName) | ||
.where('created_time', '<', cutOffDate) | ||
.delete(); | ||
}, 'EventModel::deleteOldEvents'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for withTransaction since there's only one db call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the function shouldn't return a value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
It will delete events older than the current timestamp, so yes. I don't think that's an issue given you'd have to go ahead and actively set the config as such. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @AdrienPoupa, I've just left one last comment and then we can merge
e191d09
to
cc34ff8
Compare
Revisiting https://github.com/laurent22/joplin/pull/9988/files as I had the same issue this week (my Joplin DB grew to 600mb while I only have a few notes...).
I'm using mostly the same code, but I tried to match other patterns found in the codebase (using a TTL attribute in the class, not requiring arguments in the event function).
I also handled Laurent's review to use fake timers for the test.