Skip to content
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(occ): New command to delete previews #35189

Closed
wants to merge 14 commits into from

Conversation

charleypaulus
Copy link

@charleypaulus charleypaulus commented Nov 15, 2022

Provides a new occ command to delete previews, with options:

  • to only delete previews of original files that no longer exist
  • to only delete previews of files of a specific mimetype
  • to delete previews in batches of a specified number, for database access performance purpose

Tested on NC 26, with S3 as primary object storage, and with local storage. Tested all combinations of options. Verified that previews are actually deleted from S3 storage and from filecache.

Addressing these issues (as a manual command):
#26014, #20344, #18416, #35290
@szaimen, @solracsf, @arpadmuller, @skjnldsv, @SimplyCorbett, @MorrisJobke

@solracsf
Copy link
Member

Seems promising. Tested also on local filesystem?

core/Command/Preview/Delete.php Fixed Show resolved Hide resolved
@szaimen szaimen added enhancement 3. to review Waiting for reviews labels Nov 15, 2022
@szaimen szaimen requested review from danxuliu, a team, blizzz, juliushaertl and skjnldsv and removed request for a team November 15, 2022 22:05
@charleypaulus
Copy link
Author

Seems promising. Tested also on local filesystem?

Just tested it on local storage configuration. It worked as well.

->leftJoin('a', 'filecache', 'b', $qb->expr()->eq(
$qb->expr()->castColumn('a.name', IQueryBuilder::PARAM_INT), 'b.fileid'
))
->where($and);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might still be a good idea to limit the results and rather run multiple queries after each other in a php loop to avoid massive queries against the db.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can first narrow down the preview search on the storage that holds the preview folder.

Then do you have in mind something like "SELECT ... FROM ... LIMIT a OFFSET a*x", with for loop on x? If so, do you know what a good batch size would be?

If the issue is not the mysql query size itself, but on the call for deletions, these deletions are actually done in a for loop in deletePreviews function (line 109).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was thinking about the query size itself. You wouldn't need the offset as when going through the chunk the entries would be deleted from the table so the next query with the same limit should just give you the next batch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can first narrow down the preview search on the storage that holds the preview folder.

This should still be fine to keep in the query as the storage column is indexed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can first narrow down the preview search on the storage that holds the preview folder.

This should still be fine to keep in the query as the storage column is indexed.

I updated the sql query with a condition on storage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was thinking about the query size itself. You wouldn't need the offset as when going through the chunk the entries would be deleted from the table so the next query with the same limit should just give you the next batch.

I added an option to delete previews by batch.
Two notes:

  • Batch deletion is incompatible with dry mode, as it relies on actually deleting previews (the proposed code takes care of catching these incompatible options).
  • This option makes the code not in line with lib/private/Preview/BackgroundCleanupJob.php or core/Command/Preview/ResetRenderedTexts.php that do not have a batch mode.

Copy link
Member

@juliushaertl juliushaertl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor comments, otherwise that seems reasonable :)

@charleypaulus charleypaulus force-pushed the deletePreviews branch 4 times, most recently from 7fe61cd to c37a557 Compare November 18, 2022 11:59
@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Nov 18, 2022
@skjnldsv
Copy link
Member

skjnldsv commented Nov 18, 2022

php-cs is not happy :)
Autoloader too. Please run: bash build/autoloaderchecker.sh

@charleypaulus

This comment was marked as resolved.

@tcitworld
Copy link
Member

I ran bash build/autoloaderchecker.sh. It changed 50 files, that I committed. Not sure I had to do that.

You can drop them, only add changes from lib/composer/composer/autoload_classmap.php and lib/composer/composer/autoload_static.php.

I installed phpcs on my laptop. Is there a specific rules file for Nextcloud that I should be using when running phpcs ?

It should automatically use the .php-cs-fixer.dist.php file.

This was referenced Nov 14, 2023
@blizzz blizzz modified the milestones: Nextcloud 28, Nextcloud 29 Nov 23, 2023
@tirenucci
Copy link

Hi, this PR is still active? Because i need it for fix my s3 issues 🙄

@tirenucci
Copy link

up ?

@charleypaulus
Copy link
Author

up ?

I hope it is still active. I've been waiting for review and approval.

I have fixed conflicts with latest master a few times. I can fix them again if I know there is an intention to include this PR.

@tirenucci
Copy link

up ?

I hope it is still active. I've been waiting for review and approval.

I have fixed conflicts with latest master a few times. I can fix them again if I know there is an intention to include this PR.

I hope too, in the meantime I deactivate previews...

This was referenced Mar 12, 2024
This was referenced Mar 20, 2024
@skjnldsv skjnldsv mentioned this pull request Mar 28, 2024
81 tasks
@skjnldsv skjnldsv modified the milestones: Nextcloud 29, Nextcloud 30 Mar 28, 2024
@skjnldsv skjnldsv added 2. developing Work in progress stale Ticket or PR with no recent activity and removed 3. to review Waiting for reviews labels Jul 27, 2024
This was referenced Jul 30, 2024
@solracsf solracsf changed the title Delete previews enh(occ): New command to delete previews Aug 3, 2024
@solracsf solracsf changed the title enh(occ): New command to delete previews feat(occ): New command to delete previews Aug 3, 2024
@Altahrim Altahrim mentioned this pull request Aug 5, 2024
@inetol
Copy link

inetol commented Aug 6, 2024

@charleypaulus Please fix the conflicts in this PR, it's running a little late but hopefully this will get in for NC30

@Altahrim Altahrim mentioned this pull request Aug 7, 2024
@skjnldsv skjnldsv mentioned this pull request Aug 13, 2024
@skjnldsv skjnldsv closed this Aug 14, 2024
@skjnldsv skjnldsv removed this from the Nextcloud 30 milestone Aug 14, 2024
@skjnldsv
Copy link
Member

@charleypaulus Please fix the conflicts in this PR, it's running a little late but hopefully this will get in for NC30

Too late for 30. 😕
it also seems this PR was dragging in time and still conflicting :(
Is anyone interested in taking over and re-open? We can also maybe do this in another ticket to avoid resolving conflicts.

If anyone do so, please ping me directly, I'll do my best to review ans assist to get this in in our early 31 release cycle!! 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress enhancement stale Ticket or PR with no recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.