Skip to content

Commit

Permalink
fix performance regression in all releases-views
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Jan 2, 2021
1 parent 8966c52 commit df42acb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/db/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,17 @@ pub fn migrate(version: Option<Version>, conn: &mut Client) -> CratesfyiResult<(
ALTER release_time TYPE timestamp USING release_time AT TIME ZONE 'UTC';
",
),
migration!(
context,
26,
"create index for crates.latest_version_id",
// upgrade
"
CREATE INDEX crates_latest_version_idx ON crates (latest_version_id);
ANALYZE crates;
",
"DROP INDEX crates_latest_version_idx;",
),
];

for migration in migrations {
Expand Down
3 changes: 1 addition & 2 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ pub(crate) fn get_releases(conn: &mut Client, page: i64, limit: i64, order: Orde
releases.rustdoc_status,
github_repos.stars
FROM crates
INNER JOIN releases ON crates.id = releases.crate_id
INNER JOIN releases ON crates.latest_version_id = releases.id
LEFT JOIN github_repos ON releases.github_repo = github_repos.id
WHERE
((NOT $3) OR (releases.build_status = FALSE AND releases.is_library = TRUE))
AND crates.latest_version_id = releases.id
ORDER BY {} DESC NULLS LAST
LIMIT $1 OFFSET $2",
ordering,
Expand Down

0 comments on commit df42acb

Please sign in to comment.