-
Notifications
You must be signed in to change notification settings - Fork 380
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
feat(backend revision): add clean-up note revisions job #5349
base: develop
Are you sure you want to change the base?
Conversation
Please rebase your branch to the latest version of develop to fix the CI. |
10d84da
to
1282f66
Compare
Thank you for letting me know. |
5219200
to
20dbecc
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #5349 +/- ##
===========================================
+ Coverage 57.66% 57.82% +0.16%
===========================================
Files 418 419 +1
Lines 12058 12064 +6
Branches 1007 903 -104
===========================================
+ Hits 6953 6976 +23
- Misses 5048 5088 +40
+ Partials 57 0 -57
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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 general this is a good starting point, thanks for that!
However when deleting old revisions, we need to somehow compensate the missing information, don't we? A revision holds the diff (called patch in the entity) to its preceding revision. This is used by the revision viewer to show the differences. When deleting old revisions, this results in an invalid diff. So the oldest not removed revision needs its diff be updated.
Or should we do it differently, @hedgedoc/backend @hedgedoc/frontend ?
| ---------------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------ | | ||
| `HD_REVISION_RETENTION_DAYS` | 0 | | The number of days a revision should be kept. If the config option is not set or set to 0, all revisions will be kept forever. | | ||
<!-- | ||
| `HD_IMAGE_PROXY` | - | `https://image-proxy.example.com` | **ToDo:** Add description | |
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.
Why is this env variable in the revision section?
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 did this because I thought it would be better to separate it by entity.
But maybe it should be in the notes section?
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.
@ErikMichelson I moved it from revesion section to note section!
I see, revisions have not only content but also diff (patch). I was referring to the code below that is called from the revision modal.
|
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
20dbecc
to
c06922e
Compare
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
note.publicId, | ||
revision2.content, | ||
revision3.content | ||
) |
Check notice
Code scanning / CodeQL
Semicolon insertion Note
the enclosing function
note.publicId, | ||
revision1.content, | ||
revision2.content | ||
) |
Check notice
Code scanning / CodeQL
Semicolon insertion Note
the enclosing function
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.
This seems to be something that can be fixed throughout the whole project by just running the lint-fix command (yarn lint:fix
).
6b8fe92
to
2106f68
Compare
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
2106f68
to
078dc96
Compare
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
@ErikMichelson I have implemented updating patch (content diff), so could you please review it again? |
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 your contribution and sorry again that this took a while.
I've annotated some minor things.
}, | ||
); | ||
expect(() => noteConfig()).toThrow( | ||
'"forbiddenNoteIds[0]" is not allowed to be empty', |
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.
Shouldn't we expect a different error in this case?
const restore = mockedEnv( | ||
{ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
HD_FORBIDDEN_NOTE_IDS: invalidforbiddenNoteIds.join(' , '), |
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.
Here we should use not the invalid mock data to only test one error case at once.
note.publicId, | ||
revision1.content, | ||
revision2.content | ||
) |
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.
This seems to be something that can be fixed throughout the whole project by just running the lint-fix command (yarn lint:fix
).
expect(revision3.patch).toMatchInlineSnapshot(` | ||
"Index: test-note | ||
=================================================================== | ||
--- test-note | ||
+++ test-note | ||
@@ -0,0 +1,6 @@ | ||
+--- | ||
+title: new title | ||
+description: new description | ||
+tags: [ "tag1" ] | ||
+--- | ||
+new content | ||
" | ||
`); | ||
}); |
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.
Like already stated in the other PR, I think extracting the embedded snapshots into their own "normal snapshot" file would be good.
|
||
// Delete all old revisions everyday on 0:00 AM | ||
@Cron('0 0 * * *') | ||
async handleCron(): Promise<void> { |
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 think we should rename these methods (handleCron
and handleTimeout
) to indicate that they're used in the context of revision cleanup. Maybe something like handleRevisionCleanupTimeout
etc?
return await this.removeOldRevisions(); | ||
} | ||
|
||
async removeOldRevisions(): Promise<void> { |
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.
It would be good to have a block of ESDoc here
if (!oldRevisions.length) { | ||
continue; | ||
|
||
} else if (oldRevisions.length == revisions.length - 1 ){ |
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 use explicit comparisons always (===
).
.filter( | ||
(revision) => | ||
new Date(revision.createdAt).getTime() <= | ||
currentTime - revisionRetentionDays * 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.
To improve performance, this second value could be calculated outside the loop, so before the .filter
method call.
const beUpdatedRevision = revisions.slice(-1)[0] | ||
beUpdatedRevision.patch = createPatch( | ||
note.publicId, | ||
'', // donnt exist older revision |
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.
'', // donnt exist older revision | |
'', // there is no older revision |
Component/Part
backend revision
Description
This PR adds note revisions clean-up job.
Steps
made sure that:
master
for 1.x & docs,develop
for 2.xRelated Issue(s)