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

Eagerly load statuses with the main query in Api::V1::FavouritesController #14673

Merged
merged 1 commit into from
Aug 28, 2020

Conversation

akihikodaki
Copy link
Contributor

The old implementation had two queries:

  1. The query constructed in Api::V1::FavouritesController#results.
  2. The query constructed in #cached_favourites, which is merged with 1.

Both of them are issued againt PostgreSQL. The combination of the two queries caused the following problems:

  • The small window between the two queries involves race conditions.
  • Minor performance inefficiency.

Moreover, the construction of query 2, which involves merging with query 1 has a bug. Query 1 is finalized with paginate_by_id, but paginate_by_id returns an array when min_id parameter is specified. The behavior prevents from merging the query, and in the real world, ActiveRecord simply ignores the merge (!), which results in querying the entire scan of statuses and favourites table.

This change fixes these issues by simply letting query 1 get all the works done.

…oller

The old implementation had two queries:
1. The query constructed in Api::V1::FavouritesController#results
2. The query constructed in #cached_favourites, which is merged with 1.

Both of them are issued againt PostgreSQL. The combination of the two
queries caused the following problems:
- The small window between the two queries involves race conditions.
- Minor performance inefficiency.

Moreover, the construction of query 2, which involves merging with query
1 has a bug. Query 1 is finalized with paginate_by_id, but paginate_by_id
returns an array when min_id parameter is specified. The behavior prevents
from merging the query, and in the real world, ActiveRecord simply ignores
the merge (!), which results in querying the entire scan of statuses and
favourites table.

This change fixes these issues by simply letting query 1 get all the works
done.
@akihikodaki akihikodaki added bug Something isn't working performance Runtime performance labels Aug 28, 2020
@akihikodaki
Copy link
Contributor Author

Moreover, the construction of query 2, which involves merging with query 1 has a bug. Query 1 is finalized with paginate_by_id, but paginate_by_id returns an array when min_id parameter is specified. The behavior prevents from merging the query, and in the real world, ActiveRecord simply ignores the merge (!), which results in querying the entire scan of statuses and favourites table.

For the record, the behavior is found by @abcang.

@Gargron Gargron merged commit 552e886 into mastodon:master Aug 28, 2020
thenameisnigel-old pushed a commit to ChatterlyOSE/Chatterly that referenced this pull request Sep 6, 2020
…oller (mastodon#14673)

The old implementation had two queries:
1. The query constructed in Api::V1::FavouritesController#results
2. The query constructed in #cached_favourites, which is merged with 1.

Both of them are issued againt PostgreSQL. The combination of the two
queries caused the following problems:
- The small window between the two queries involves race conditions.
- Minor performance inefficiency.

Moreover, the construction of query 2, which involves merging with query
1 has a bug. Query 1 is finalized with paginate_by_id, but paginate_by_id
returns an array when min_id parameter is specified. The behavior prevents
from merging the query, and in the real world, ActiveRecord simply ignores
the merge (!), which results in querying the entire scan of statuses and
favourites table.

This change fixes these issues by simply letting query 1 get all the works
done.
thenameisnigel-old pushed a commit to ChatterlyOSE/Chatterly that referenced this pull request Sep 7, 2020
…oller (mastodon#14673)

The old implementation had two queries:
1. The query constructed in Api::V1::FavouritesController#results
2. The query constructed in #cached_favourites, which is merged with 1.

Both of them are issued againt PostgreSQL. The combination of the two
queries caused the following problems:
- The small window between the two queries involves race conditions.
- Minor performance inefficiency.

Moreover, the construction of query 2, which involves merging with query
1 has a bug. Query 1 is finalized with paginate_by_id, but paginate_by_id
returns an array when min_id parameter is specified. The behavior prevents
from merging the query, and in the real world, ActiveRecord simply ignores
the merge (!), which results in querying the entire scan of statuses and
favourites table.

This change fixes these issues by simply letting query 1 get all the works
done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Runtime performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants