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

🎁 Adding DerivativeRodeoService#cleanup_derivatives ♻️ #271

Merged
merged 1 commit into from
Jul 27, 2023

Conversation

jeremyf
Copy link
Contributor

@jeremyf jeremyf commented Jul 27, 2023

Apologies in advance, this commit conflates two things, but I'll explain.

This commit is in service of completing the DerivativeService interface; namely the #cleanup_derivatives method.

Originally, I was thinking I would only delete the derivatives generated by this service. So I began refactoring to reduce duplicated knowledge. That refactor meant extracting #named_derivatives_and_generators, and as a matter of hygiene and legibility, I moved the method closer to the configuration. The hope being that if one thing changes the other might.

This then involved rethinking the #create_derivatives and #cleanup_derivatives to use this new method. I was looking for symmetry in method implementation (e.g. loop over the named derivatives and either create them or delete them).

However, as I looked at the other reference implementations I noticed that I could get all of the derivatives by calling Hyrax::DerivativePath.derivatives_for_reference (see code). I spent a bit of time thinking, as the comments indicate, as to which approach to take: delete all derivatives OR only those that would be created by the present configuration.

It makes sense to me to delete all of them, in part due to the implementation details of finding the correct valid? derivative service but also the fact that any valid? service is subject to configuration, which might change over time, and thus leave orphaned derivatives dangling in the file system.

Closes #270

Related to:

Apologies in advance, this commit conflates two things, but I'll
explain.

This commit is in service of completing the DerivativeService interface;
namely the `#cleanup_derivatives` method.

Originally, I was thinking I would only delete the derivatives generated
by this service.  So I began refactoring to reduce knowledge.  That
refactor meant extracting `#named_derivatives_and_generators`, and as a
matter of hygiene and legibility, I moved the method closer to the
configuration.  The hope being that if one thing changes the other
might.

This then involved rethinking the `#create_derivatives` and
`#cleanup_derivatives` to use this new method.  I was looking for
symmetry in method implementation (e.g. loop over the named derivatives
and either create them or delete them).

However, as I looked at the other reference implementations I noticed
that I could get all of the derivatives by calling
`Hyrax::DerivativePath.derivatives_for_reference` ([see code][1]).  I
spent a bit of time thinking, as the comments indicate, as to which
approach to take: delete all derivatives OR only those that would be
created by the present configuration.

It makes sense to me to delete all of them, in part due to the
implementation details of finding the correct `valid?` derivative
service but also the fact that any `valid?` service is subject to
configuration, which might change over time, and thus leave orphaned
derivatives dangling in the file system.

Closes #270

Related to:

- notch8/derivative_rodeo#56

[1]:https://github.com/samvera/hyrax/blob/b28d8ff35d2fb708483d2ce0c4e687450b7f5aef/app/services/hyrax/derivative_path.rb#L14-L18
@jeremyf jeremyf force-pushed the handling-derivative-cleanup branch from f93b284 to 2536e37 Compare July 27, 2023 15:43
@jeremyf jeremyf merged commit 9e7837c into main Jul 27, 2023
@jeremyf jeremyf deleted the handling-derivative-cleanup branch July 27, 2023 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add IiifPrint::DerivativeRodeoService#cleanup_derivatives
2 participants