diff --git a/db/90-views.sql b/db/90-views.sql index b0d3f72..14896b0 100644 --- a/db/90-views.sql +++ b/db/90-views.sql @@ -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); $$; /* diff --git a/src/queries.ts b/src/queries.ts index 5c7c7fd..9b1712d 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -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 = {