Move ordering from views to queries.ts
Turns out views aren't guaranteed to keep their order ¯\_(ツ)_/¯ Fixes #24master
parent
354eddb673
commit
4607eaf307
|
@ -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
|
SELECT url,COALESCE(videoTitle,url) AS title,displayName AS requester,imageUrl,state,score,reqTimestamp FROM requests
|
||||||
JOIN requestMetadata USING (url)
|
JOIN requestMetadata USING (url)
|
||||||
JOIN scores USING (url)
|
JOIN scores USING (url)
|
||||||
JOIN users ON requests.requester = users.userid
|
JOIN users ON requests.requester = users.userid;
|
||||||
ORDER BY score DESC, reqTimestamp ASC;
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION get_requests_voted(votinguserid int)
|
CREATE OR REPLACE FUNCTION get_requests_voted(votinguserid int)
|
||||||
RETURNS TABLE (
|
RETURNS TABLE (
|
||||||
|
@ -21,8 +20,7 @@ CREATE OR REPLACE FUNCTION get_requests_voted(votinguserid int)
|
||||||
SELECT url,title,requester,imageUrl,state,score,reqTimestamp,
|
SELECT url,title,requester,imageUrl,state,score,reqTimestamp,
|
||||||
(CASE WHEN votes.userid IS NULL THEN FALSE ELSE TRUE END) AS voted
|
(CASE WHEN votes.userid IS NULL THEN FALSE ELSE TRUE END) AS voted
|
||||||
FROM requests_vw
|
FROM requests_vw
|
||||||
LEFT JOIN votes ON (requests_vw.url = votes.requesturl AND votes.userid = votinguserid)
|
LEFT JOIN votes ON (requests_vw.url = votes.requesturl AND votes.userid = votinguserid);
|
||||||
ORDER BY score DESC, reqTimestamp ASC;
|
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -57,24 +57,26 @@ export const getRequests = {
|
||||||
name: "getRequests",
|
name: "getRequests",
|
||||||
text: "SELECT * FROM requests_vw \
|
text: "SELECT * FROM requests_vw \
|
||||||
JOIN states ON requests_vw.state = states.state \
|
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 = {
|
export const getRequestsVoted = {
|
||||||
name: "getRequestsVoted",
|
name: "getRequestsVoted",
|
||||||
text: "SELECT * FROM get_requests_voted($2) \
|
text: "SELECT * FROM get_requests_voted($2) \
|
||||||
JOIN states ON get_requests_voted.state = states.state \
|
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 = {
|
export const getAllRequests = {
|
||||||
name: "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 = {
|
export const getAllRequestsVoted = {
|
||||||
name: "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 = {
|
export const checkRequestExists = {
|
||||||
|
@ -137,7 +139,7 @@ export const getAndLockCronJob = {
|
||||||
text: `SELECT * FROM cron
|
text: `SELECT * FROM cron
|
||||||
WHERE (lastSuccess + runInterval) < now()
|
WHERE (lastSuccess + runInterval) < now()
|
||||||
AND jobName = $1
|
AND jobName = $1
|
||||||
FOR UPDATE SKIP LOCKED;`
|
FOR UPDATE SKIP LOCKED`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateCronJobLastSuccess = {
|
export const updateCronJobLastSuccess = {
|
||||||
|
|
Loading…
Reference in New Issue