The first version of filter duplicate boosts forgot to take the max of only local or remote scopes, so if a post had been boosted more recently by a remote account, the most recent local boost wouldn't be seen and vice versa for the federated feed. This fixes that by including those scopes in the correlated subquery.
Caveats:
I was able to figure out how to express correlated subqueries using Arel, but try as I might, I wasn't able to figure out how to change the table alias of the contexts from Status when used in the subquery (so rather than WHERE s2.local = true it would always be WHERE statuses.local = true, which didn't work). This means that if the definition of the contexts change, then our subquery will get out of sync, but if that happens the tests should catch us.
Other changes
Add a multicolumn index on reblog_of_id and id to make subquery faster!
Move the scope.merge! call out of the block of other scopes so that it's easier to maintain - fewer merge conflicts
split scope into two scopes to match rest of structure which only has one scope per method
remove crappy sleep hack to ensure monotonic increase of IDs, just manually increment them.
explicit rspec contexts for local and remote feeds
I am not sure why the ruby linting is failing now, but i didn't touch any of those files - we'll sort of linter errors when we merge upstream tomorrow
Closes: https://github.com/NeuromatchAcademy/mastodon/issues/37 Continues: https://github.com/NeuromatchAcademy/mastodon/pull/36
The first version of filter duplicate boosts forgot to take the max of only local or remote scopes, so if a post had been boosted more recently by a remote account, the most recent local boost wouldn't be seen and vice versa for the federated feed. This fixes that by including those scopes in the correlated subquery.
Caveats:
Status
when used in the subquery (so rather thanWHERE s2.local = true
it would always beWHERE statuses.local = true
, which didn't work). This means that if the definition of the contexts change, then our subquery will get out of sync, but if that happens the tests should catch us.Other changes
reblog_of_id
andid
to make subquery faster!scope.merge!
call out of the block of other scopes so that it's easier to maintain - fewer merge conflictsI am not sure why the ruby linting is failing now, but i didn't touch any of those files - we'll sort of linter errors when we merge upstream tomorrow