Move ordering from views to queries.ts

Turns out views aren't guaranteed to keep their order ¯\_(ツ)_/¯

Fixes #24
master
Dessa Simpson 2021-02-24 20:28:02 -07:00
parent 354eddb673
commit 4607eaf307
2 changed files with 9 additions and 9 deletions

View File

@ -2,8 +2,7 @@ CREATE OR REPLACE VIEW requests_vw AS
SELECT url,COALESCE(videoTitle,url) AS title,displayName AS requester,imageUrl,state,score,reqTimestamp FROM requests
JOIN requestMetadata USING (url)
JOIN scores USING (url)
JOIN users ON requests.requester = users.userid
ORDER BY score DESC, reqTimestamp ASC;
JOIN users ON requests.requester = users.userid;
CREATE OR REPLACE FUNCTION get_requests_voted(votinguserid int)
RETURNS TABLE (
@ -21,8 +20,7 @@ CREATE OR REPLACE FUNCTION get_requests_voted(votinguserid int)
SELECT url,title,requester,imageUrl,state,score,reqTimestamp,
(CASE WHEN votes.userid IS NULL THEN FALSE ELSE TRUE END) AS voted
FROM requests_vw
LEFT JOIN votes ON (requests_vw.url = votes.requesturl AND votes.userid = votinguserid)
ORDER BY score DESC, reqTimestamp ASC;
LEFT JOIN votes ON (requests_vw.url = votes.requesturl AND votes.userid = votinguserid);
$$;
/*

View File

@ -57,24 +57,26 @@ export const getRequests = {
name: "getRequests",
text: "SELECT * FROM requests_vw \
JOIN states ON requests_vw.state = states.state \
WHERE active LIMIT $1"
WHERE active ORDER BY score DESC, reqTimestamp ASC LIMIT $1"
}
export const getRequestsVoted = {
name: "getRequestsVoted",
text: "SELECT * FROM get_requests_voted($2) \
JOIN states ON get_requests_voted.state = states.state \
WHERE active LIMIT $1"
WHERE active ORDER BY score DESC, reqTimestamp ASC LIMIT $1"
}
export const getAllRequests = {
name: "getAllRequests",
text: "SELECT * FROM requests_vw LIMIT $1"
text: "SELECT * FROM requests_vw \
ORDER BY score DESC, reqTimestamp ASC LIMIT $1"
}
export const getAllRequestsVoted = {
name: "getAllRequestsVoted",
text: "SELECT * FROM get_requests_voted($2) LIMIT $1"
text: "SELECT * FROM get_requests_voted($2) \
ORDER BY score DESC, reqTimestamp ASC LIMIT $1"
}
export const checkRequestExists = {
@ -137,7 +139,7 @@ export const getAndLockCronJob = {
text: `SELECT * FROM cron
WHERE (lastSuccess + runInterval) < now()
AND jobName = $1
FOR UPDATE SKIP LOCKED;`
FOR UPDATE SKIP LOCKED`
}
export const updateCronJobLastSuccess = {