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

Use a rake task to delete cached attachments #4596

Merged
merged 1 commit into from
Aug 2, 2021

Conversation

javierm
Copy link
Member

@javierm javierm commented Jul 26, 2021

Background

Our previous system to delete cached attachments didn't work for documents because the custom_hash_data is different for files created from a file and files created from cached attachments.

When creating a document attachment, the name of the file is taken into account to calculate the hash. Let's say the original file name is "logo.pdf", and the generated hash is "123456". The cached attachment will be "123456.pdf", so the generated hash using the cached attachment will be something different, like "28af3". So the file that will be removed will be "28af3.pdf", and not "123456.pdf", which will still be present.

Furthermore, there are times where users choose a file and then they close the browser or go to a different page. In those cases, we weren't deleting the cached attachments either.

Objectives

  • Fix a bug where cached document attachments weren't correctly deleted
  • Improve the user experience removing a cached attachment by making it instantaneous

Notes

There's related a bug in documents: when editing a record (for example, a proposal), if the title of the document changes, its hash changes, and so it will be impossible to generate a link to that document. Changing the way this hash is generated is not an option because it would break links to existing files. We'll fix it when moving to Active Storage in pull request #4600.

@javierm javierm self-assigned this Jul 26, 2021
@javierm javierm added this to Reviewing in Consul Democracy via automation Jul 26, 2021
@javierm javierm force-pushed the cached_attachments_task branch 3 times, most recently from 4aabfd4 to a0b372f Compare July 27, 2021 21:57
@taitus taitus self-assigned this Jul 30, 2021
@javierm javierm force-pushed the cached_attachments_task branch 2 times, most recently from 9fd4f11 to 930bb75 Compare July 30, 2021 15:28
Our previous system to delete cached attachments didn't work for
documents because the `custom_hash_data` is different for files created
from a file and files created from cached attachments.

When creating a document attachment, the name of the file is taken into
account to calculate the hash. Let's say the original file name is
"logo.pdf", and the generated hash is "123456". The cached attachment
will be "123456.pdf", so the generated hash using the cached attachment
will be something different, like "28af3". So the file that will be
removed will be "28af3.pdf", and not "123456.pdf", which will still be
present.

Furthermore, there are times where users choose a file and then they
close the browser or go to a different page. In those cases, we weren't
deleting the cached attachments either.

So we're adding a rake task to delete these files once a day. This way
we can simplify the logic we were using to destroy cached attachments.

Note there's related a bug in documents: when editing a record (for
example, a proposal), if the title of the document changes, its hash
changes, and so it will be impossible to generate a link to that
document. Changing the way this hash is generated is not an option
because it would break links to existing files. We'll try to fix it when
moving to Active Storage.
Consul Democracy automation moved this from Reviewing to Testing Aug 2, 2021
@javierm javierm merged commit 743dc27 into master Aug 2, 2021
Consul Democracy automation moved this from Testing to Release 1.4.0 Aug 2, 2021
@javierm javierm deleted the cached_attachments_task branch August 2, 2021 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants