-
Notifications
You must be signed in to change notification settings - Fork 51
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 JSON string array of ids instead of ordered_aggregation linked list #5778
base: develop
Are you sure you want to change the base?
Conversation
34c3f33
to
71f68e7
Compare
e5dcb7c
to
5fadc1b
Compare
5b23684
to
c1768fe
Compare
f434642
to
dc1bc63
Compare
f71b199
to
5828937
Compare
…ids and rename variables where appropriate as well
5828937
to
efb8b83
Compare
65e3815
to
1787dc9
Compare
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.
As far as I can tell this looks good. I do have a couple clarifying questions and some small suggestions.
spec/factories/media_objects.rb
Outdated
@@ -49,6 +49,7 @@ | |||
rights_statement { ['http://rightsstatements.org/vocab/InC-EDU/1.0/'] } | |||
terms_of_use { [ 'Terms of Use: Be kind. Rewind.' ] } | |||
series { [Faker::Lorem.word] } | |||
master_files { [] } |
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.
Should this be sections { [] }
?
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.
Good question.
I don't think so? I think it is needed to initialize that association for tests that were depending on it. But I could try switching it and see if the tests still pass.
@attrs[:section_id] = solr_document["section_id_ssim"] | ||
@attrs[:section_ids] = solr_document["section_id_ssim"] |
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.
Do these need to be separate fields? Seems weird to have a field with a singular name that contains the same data as a field with the pluralized name.
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 they do because adding @attrs[:section_ids]
allows this presenter to proxy the new MediaObject#section_ids
method. Alternatively this presenter could delegate section_ids
to section_id
or implement a new method which returns section_id
. Do you think either of those would make more sense? I didn't want to remove section_id
from the attributes because we had already added it so I know it is used elsewhere although I can't remember exactly where.
spec/models/media_object_spec.rb
Outdated
it 'migrates to section_list without interaction' do | ||
expect(media_object.section_list).to eq nil | ||
mo = MediaObject.find(media_object.id) | ||
mo.save | ||
mo = MediaObject.find(media_object.id) | ||
expect(mo.section_list).not_to eq nil | ||
expect(mo.sections).to eq [section, section2] | ||
expect(mo.section_ids).to eq [section.id, section2.id] | ||
end |
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'm not sure I understand what exactly this test case is for? Is it just that section_list
fields are persisted?
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 you're right that this test only shows that section_list
persists. I added a test to show that when section_list
is set a MediaObject won't use ordered_master_files
anymore. This new test plus the one above which shows that MediaObject will read from ordered_master_files
to populate section_list
when it isn't set should probably cover all cases so I removed this test.
spec/models/media_object_spec.rb
Outdated
expect(mo.ordered_master_files.to_a).to eq [section, section2] | ||
expect(mo.ordered_master_file_ids).to eq [section.id, section2.id] | ||
expect(mo.sections).to eq [section, section2] | ||
expect(mo.section_ids).to eq [section.id, section2.id] |
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.
Instead of explicitly testing for all those specific arrays, would it make sense to condense this to equality checks?
expect(mo.ordered_master_files.to_a).to eq [section, section2] | |
expect(mo.ordered_master_file_ids).to eq [section.id, section2.id] | |
expect(mo.sections).to eq [section, section2] | |
expect(mo.section_ids).to eq [section.id, section2.id] | |
expect(mo.sections).to eq mo.ordered_master_files.to_a | |
expect(mo.section_ids).to eq mo.ordered_master_file_ids |
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 like this change, but I think I'd also like to keep one of the expectations to ensure that mo.ordered_master_files
is actually populated the way I'm expecting.
Create a new property on media objects which store a JSON serialized array of ids:
section_list
. This property and related methods,sections
andsection_ids
, replace nearly all calls tomaster_files
,ordered_master_files
, andindexed_master_files
methods along with their*_ids
counterparts. The only calls left to these methods are in the migration to the new property and one instance in MediaObjectsController that I wasn't able to figure out how to remove.In order to migrate a media object it needs to be saved thus a full migration of all media objects might take too long to be done during a maintenance window. For this reason migrating is done in-place and lazily. When a media object is loaded from fedora it is migrated in-memory and made final on save. Subsequent loads from fedora use the already migrated
section_list
and should not attempt to read fromlist_source
. After some time a portion of the repository should have been migrated naturally and a follow-up background job can be setup to force migration of the remainder of media objects. A future version of Avalon that requires the migration is complete might remove theordered_aggregation
andmaster_files
association entirely.While implementing this change I wanted to ensure that edits to
section_list
/sections
/section_ids
are in-memory only until saving. Previously changes tomaster_files
andordered_master_files
were persisted immediately. In order to avoid that I put the synchronization ofsection_list
andmaster_files
into abefore_save
callback. This did cause some complications because that synchronization can lead to saves when objects were in odd states in the test suite. This was a reason for doing the switch of all references tomaster_files
tosections
throughout the code base. The only place I wasn't able to resolve this was inMediaObjectsController#update_media_object
. One thing to be aware of is that because of this synchronization you may need to reload the media object after saving in order to get the updatedmaster_files
loaded. (SeeMasterFile#media_object=
for an example of this.)Review notes:
app/models/media_object.rb
andapp/models/master_file.rb
It probably makes sense to squash this PR when merging.
Resolves #5749
Future work: