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

🎁 Introduce .named_derivatives_and_generators_filter #306

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

jeremyf
Copy link
Contributor

@jeremyf jeremyf commented Nov 29, 2023

Prior to this commit, IIIF Print assumed that every file of a given
mime-type would use all of the same generators. However, that is not
necessarily the case.

With this commit:

  • Updated documentation based on a read of the generated Yardoc
  • Added DerivativeRodeoService.named_derivatives_and_generators_filter
  • Added a clone of attributes

The clone is in place to help ensure that as we apply the filter we
don't accidentally delete the application's configuration for mime
category and expected derivatives.

For example, let's say I have the following nested hash:

nested_hash = {
  pdf: {
    thumbnail: "DerivativeRodeo::Generators::ThumbnailGenerator"
  },
  image: {
    thumbnail: "DerivativeRodeo::Generators::ThumbnailGenerator",
    json: "DerivativeRodeo::Generators::WordCoordinatesGenerator",
    xml: "DerivativeRodeo::Generators::AltoGenerator",
    txt: "DerivativeRodeo::Generators::PlainTextGenerator"
  }
}

If I then call the following:

nested_hash.fetch(:pdf).delete_if { |key, value| key == :thumbnail }

Then look at nested_hash, I will see the following:

pp nested_hash

{:pdf=>{},
 :image=>
  {:thumbnail=>"DerivativeRodeo::Generators::ThumbnailGenerator",
   :json=>"DerivativeRodeo::Generators::WordCoordinatesGenerator",
   :xml=>"DerivativeRodeo::Generators::AltoGenerator",
   :txt=>"DerivativeRodeo::Generators::PlainTextGenerator"}}

Why? Because we haven't changed objects. It's possible that Rails's
class_attribute will do deep clones of hashes, but with this clone
behavior we remove that possibility of a problem.

Related to:

Prior to this commit, IIIF Print assumed that every file of a given
mime-type would use all of the same generators.  However, that is not
necessarily the case.

With this commit:

- Updated documentation based on a read of the generated Yardoc
- Added `DerivativeRodeoService.named_derivatives_and_generators_filter`
- Added a `clone` of attributes

The clone is in place to help ensure that as we apply the filter we
don't accidentally delete the application's configuration for mime
category and expected derivatives.

For example, let's say I have the following nested hash:

```ruby
nested_hash = {
  pdf: {
    thumbnail: "DerivativeRodeo::Generators::ThumbnailGenerator"
  },
  image: {
    thumbnail: "DerivativeRodeo::Generators::ThumbnailGenerator",
    json: "DerivativeRodeo::Generators::WordCoordinatesGenerator",
    xml: "DerivativeRodeo::Generators::AltoGenerator",
    txt: "DerivativeRodeo::Generators::PlainTextGenerator"
  }
}
```

If I then call the following:

```ruby
nested_hash.fetch(:pdf).delete_if { |key, value| key == :thumbnail }
```

Then look at `nested_hash`, I will see the following:

```ruby
pp nested_hash

{:pdf=>{},
 :image=>
  {:thumbnail=>"DerivativeRodeo::Generators::ThumbnailGenerator",
   :json=>"DerivativeRodeo::Generators::WordCoordinatesGenerator",
   :xml=>"DerivativeRodeo::Generators::AltoGenerator",
   :txt=>"DerivativeRodeo::Generators::PlainTextGenerator"}}
```

Why? Because we haven't changed objects.  It's possible that Rails's
class_attribute will do deep clones of hashes, but with this clone
behavior we remove that possibility of a problem.

Related to:

- notch8/adventist-dl#684
- https://github.com/scientist-softserv/adventist-dl/issues/676
@jeremyf jeremyf force-pushed the introduce-predicate-configuration-for-iiif-print branch from b2c0220 to 0183b78 Compare November 29, 2023 17:19
Copy link
Contributor

@kirkkwang kirkkwang left a comment

Choose a reason for hiding this comment

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

Worked for me!

@kirkkwang kirkkwang merged commit 5c5fa68 into main Nov 29, 2023
9 checks passed
@kirkkwang kirkkwang deleted the introduce-predicate-configuration-for-iiif-print branch November 29, 2023 17:45
kirkkwang added a commit to notch8/adventist-dl that referenced this pull request Nov 29, 2023
We were seeing that our thumbnail files were getting word coordinates
derivatives, which is a waste of processing time.  The jobs would
eventually fail but ideally we don't want them to run at all for
thumbnails.

This commit will upgrade to the latest version of IIIF Print where a new
configurable class attribute has been added to enable a more granular
control over which derivatives are run on what files.

Also in this commit, we were seeing a nilClass error for a logger in
development, so that has also been fixed.

Ref:
  - https://github.com/scientist-softserv/adventist-dl/issues/676
  - notch8/iiif_print#306
kirkkwang added a commit to notch8/adventist-dl that referenced this pull request Nov 29, 2023
We were seeing that our thumbnail files were getting word coordinates
derivatives, which is a waste of processing time.  The jobs would
eventually fail but ideally we don't want them to run at all for
thumbnails.

This commit will upgrade to the latest version of IIIF Print where a new
configurable class attribute has been added to enable a more granular
control over which derivatives are run on what files.

Also in this commit, we were seeing a nilClass error for a logger in
development, so that has also been fixed.

Ref:
  - https://github.com/scientist-softserv/adventist-dl/issues/676
  - notch8/iiif_print#306
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.

2 participants