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

AO3-5023 Fix collections displaying too many times for works #2940

Merged
merged 7 commits into from Jun 17, 2017

Conversation

HazelGrant
Copy link
Contributor

@HazelGrant HazelGrant commented Jun 15, 2017

Pull Request Checklist

  • Have you read How to write the perfect pull request?
  • Have you read through the contributor guidelines?
  • Have you added tests for any changed functionality?
  • Have you added the JIRA issue number as the first thing in your pull request title (eg: AO3-1234 Fix thing)
  • Have you updated the JIRA issue with the information below?

Issue

https://otwarchive.atlassian.net/browse/AO3-5023

Purpose

What does this PR do?

This PR fixes the issue where the same collection was showing up multiple times on a given work's collections page.

The first fix is using .includes instead of .joins in collection scopes that should return collections (not collection items) based on their approval status.

This raised a bug caused by queries in the collections and works controllers that use .includes(:approved_collections), which is including a scoped set of collections based on a join table in the includes - this tends to blow up when combined with other scopes. I've fixed this by explicitly spelling out how the :approved_collections work - to .includes(collections: [:collection_items]).where(collection_items: { user_approval_status: CollectionItem::APPROVED, collection_approval_status: CollectionItem::APPROVED }).

Work.includes(:approved_collections).references(:collection_items) will run the expected query (although that could cause some confusion because it's not precisely clear why the references(:collection_items) has to be there without context).

Work.includes(:approved_collections).references(:item_collections).in_collection(@collection) (and other variations, rearranging the order the methods are chained in or adding different scopes like the ones present in the two controllers) blow up with the error ActiveRecord::AssociationNotFoundError: Association named 'collection_items' was not found on CollectionItem. I'm happy to talk more about this if there are concerns with the solution in this PR.

Testing

How can the Archive's QA team verify that this is working as you intended? (If you have access, please copy this into the JIRA ticket for them!)

Locally -

  1. Find a collection in the console that has more than one work
  2. Go to the collections page for one of those works (/works/work_id/collections)
  3. Check that the collection found in step 1 only shows up once

In staging - go to http://test.archiveofourown.org/works/1064145/collections and ensure that the collection ModeratedUnrevealedTwoWorks shows up only once.

References

Are there any other relevant issues / PRs / mailing lists discussions related to this?

Credit

What name do you want us to use to credit your work in the Archive of Our Own's Release Notes?

Wendy Randquist - Littlelines

What pronouns do you prefer (she/her, he/him, zie/hir etc)?

she/her

(if you do not fill this in, we will use your GitHub account name and will use "they" to avoid making assumptions about your gender)

.where(
collection_items: {
user_approval_status: CollectionItem::REJECTED
}
)
.references(:collection_items)

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.

.where(
collection_items: {
user_approval_status: CollectionItem::APPROVED
}
)
.references(:collection_items)

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.

.where(
collection_items: {
user_approval_status: CollectionItem::APPROVED,
collection_approval_status: CollectionItem::APPROVED
}
)
.references(:collection_items)

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.

.where(
collection_items: {
user_approval_status: CollectionItem::REJECTED
}
)
.references(:collection_items)

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.

.where(
collection_items: {
user_approval_status: CollectionItem::APPROVED
}
)
.references(:collection_items)

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.

.where(
collection_items: {
user_approval_status: CollectionItem::APPROVED,
collection_approval_status: CollectionItem::APPROVED
}
)
.references(:collection_items)

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.

Copy link
Member

@sarken sarken left a comment

Choose a reason for hiding this comment

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

It looks like the changes in the works controller might be causing two test failures -- I restarted the build on Travis, but it unfortunately still failed.

@sarken sarken added the Priority: High - Broken on Test Merge immediately after approval label Jun 16, 2017
@sarken sarken changed the title Ao3 5023 rails 4 dot 2 bugfix AO3-5023 Fix collections displaying too many times for works Jun 17, 2017
Copy link
Member

@sarken sarken left a comment

Choose a reason for hiding this comment

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

Yay, thank you!

@sarken sarken added Reviewed: Ready to Merge Priority: High - Broken on Test Merge immediately after approval and removed Priority: High - Broken on Test Merge immediately after approval labels Jun 17, 2017
@sarken sarken merged commit 05e915f into otwcode:master Jun 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants