Query optimization (#235)

* Optimize version queries and decrease some query complexity

* Run formatter
This commit is contained in:
Geometrically
2021-08-20 16:33:09 -07:00
committed by GitHub
parent 07226c6d21
commit ffd9a34cf5
15 changed files with 1068 additions and 1138 deletions

View File

@@ -377,7 +377,7 @@ pub async fn get_versions_from_hashes(
"
SELECT h.hash hash, h.algorithm algorithm, f.version_id version_id FROM hashes h
INNER JOIN files f ON h.file_id = f.id
WHERE h.algorithm = $2 AND h.hash IN (SELECT * FROM UNNEST($1::bytea[]))
WHERE h.algorithm = $2 AND h.hash = ANY($1::bytea[])
",
hashes_parsed.as_slice(),
file_data.algorithm
@@ -425,7 +425,7 @@ pub async fn download_files(
SELECT f.url url, h.hash hash, h.algorithm algorithm, f.version_id version_id, v.mod_id project_id FROM hashes h
INNER JOIN files f ON h.file_id = f.id
INNER JOIN versions v ON v.id = f.version_id
WHERE h.algorithm = $2 AND h.hash IN (SELECT * FROM UNNEST($1::bytea[]))
WHERE h.algorithm = $2 AND h.hash = ANY($1::bytea[])
",
hashes_parsed.as_slice(),
file_data.algorithm
@@ -476,7 +476,7 @@ pub async fn update_files(
SELECT f.url url, h.hash hash, h.algorithm algorithm, f.version_id version_id, v.mod_id project_id FROM hashes h
INNER JOIN files f ON h.file_id = f.id
INNER JOIN versions v ON v.id = f.version_id
WHERE h.algorithm = $2 AND h.hash IN (SELECT * FROM UNNEST($1::bytea[]))
WHERE h.algorithm = $2 AND h.hash = ANY($1::bytea[])
",
hashes_parsed.as_slice(),
update_data.algorithm