diff --git a/RELEASE.md b/RELEASE.md
index c60d7c9..f1c186f 100644
--- a/RELEASE.md
+++ b/RELEASE.md
@@ -12,19 +12,9 @@ If the answer to any of the above is yes, then the release MUST be a major or mi
- [ ] Add a commit which adds a database upgrade script at `db/upgrade/[oldversion]-[newversion].sql`
- ALWAYS use a transaction for the entirety of this file
- At minimum, DB version must be bumped
- - Test the upgrade script as follows:
- ```
- git checkout [previous release tag]
- docker-compose down
- docker-compose up
- psql -h 0 -U postgres < db/upgrade/v[previous]-v[current].sql
- ```
- Update the version in `src/version.ts` and verify the app works as expected.
-- [ ] Add a commit which bumps the version in `src/version.ts` and `db/00-version.sql`, entitled `Bump version to vMAJOR.MINOR`
+- [ ] Add a commit which bumps the version in `app/version.ts` and `db/00-version.sql`
- [ ] Tag the latest commit with `vMAJOR.MINOR`
-- [ ] Write release notes
## Patch Releases
-- [ ] Add a commit which bumps the patch level in `src/version.ts`, entitled `Bump version to vMAJOR.MINOR.PATCH`
+- [ ] Add a commit which bumps the patch level in `app/version.ts`
- [ ] Tag the latest commit with `vMAJOR.MINOR.PATCH`
-- [ ] Write release notes
\ No newline at end of file
diff --git a/db/00-version.sql b/db/00-version.sql
index 6686897..4feebed 100644
--- a/db/00-version.sql
+++ b/db/00-version.sql
@@ -8,4 +8,4 @@ CREATE OR REPLACE FUNCTION get_version() RETURNS VARCHAR
AS $$SELECT major || '.' || minor FROM version $$
LANGUAGE SQL;
-INSERT INTO version (major,minor) VALUES (0,8);
+INSERT INTO version (major,minor) VALUES (0,4);
diff --git a/db/05-config.sql b/db/05-config.sql
index 2e830ab..1c4b65a 100644
--- a/db/05-config.sql
+++ b/db/05-config.sql
@@ -1,14 +1,12 @@
CREATE TABLE config (
rowlock bool DEFAULT TRUE UNIQUE NOT NULL CHECK (rowlock = TRUE),
- normaluservotepoints int NOT NULL DEFAULT 10,
- followervotepoints int NOT NULL DEFAULT 50,
- subscribervotepoints int NOT NULL DEFAULT 100,
- normaluserratelimit int NOT NULL DEFAULT 1,
- followerratelimit int NOT NULL DEFAULT 2,
- subscriberratelimit int NOT NULL DEFAULT 3,
- title varchar NOT NULL DEFAULT '{username}''s Learn Request Queue',
- colors jsonb NOT NULL DEFAULT '{"bg": {"primary": "#444444","table": "#282828","navbar": "#666666","error": "#ff0000"},"fg": {"primary": "#dddddd","ahover": "#ffffff","title": "#eeeeee"}}',
+ normaluservotepoints int NOT NULL,
+ followervotepoints int NOT NULL,
+ subscribervotepoints int NOT NULL,
+ title varchar NOT NULL,
+ colors jsonb NOT NULL,
PRIMARY KEY (rowLock)
);
-INSERT INTO config (rowlock) VALUES (true);
+INSERT INTO config (normalUserVotePoints,followerVotePoints,subscriberVotePoints,title,colors)
+ VALUES (10,50,100,'{username}''s Learn Request Queue','{"bg": {"primary": "#444444","table": "#282828","navbar": "#666666","error": "#ff0000"},"fg": {"primary": "#dddddd","ahover": "#ffffff","title": "#eeeeee"}}');
diff --git a/db/10-cron.sql b/db/10-cron.sql
index a0b1941..3493563 100644
--- a/db/10-cron.sql
+++ b/db/10-cron.sql
@@ -8,6 +8,4 @@ CREATE TABLE cron (
INSERT INTO cron (jobName,runInterval) VALUES
('processBans','30 minutes'),
-('processFollows','30 minutes'),
-('processSubscriptions','30 minutes'),
('processEmptyMetadata','1 day');
diff --git a/db/10-users.sql b/db/10-users.sql
index 7774265..dc0aef7 100644
--- a/db/10-users.sql
+++ b/db/10-users.sql
@@ -2,5 +2,7 @@ CREATE TABLE users (
userId int NOT NULL,
displayName varchar NOT NULL,
imageUrl varchar,
+ isFollower boolean NOT NULL DEFAULT FALSE,
+ isSubscriber boolean NOT NULL DEFAULT FALSE,
PRIMARY KEY (userId)
);
diff --git a/db/15-streamer.sql b/db/15-streamer.sql
index b39604c..53068c8 100644
--- a/db/15-streamer.sql
+++ b/db/15-streamer.sql
@@ -3,4 +3,4 @@ CREATE TABLE streamer (
tokenPair json,
PRIMARY KEY (userid),
FOREIGN KEY (userid) REFERENCES users(userid)
-);
+)
diff --git a/db/20-requests.sql b/db/20-requests.sql
index b63c359..c3f3cf5 100644
--- a/db/20-requests.sql
+++ b/db/20-requests.sql
@@ -1,5 +1,5 @@
CREATE TABLE requests (
- url varchar NOT NULL,
+ url varchar NOT NULL UNIQUE,
requester int NOT NULL,
state varchar NOT NULL DEFAULT 'Requested',
reqTimestamp timestamptz NOT NULL DEFAULT NOW(),
diff --git a/db/30-votes.sql b/db/30-votes.sql
index 8da76f0..0b878ba 100644
--- a/db/30-votes.sql
+++ b/db/30-votes.sql
@@ -1,6 +1,6 @@
CREATE TABLE votes (
- requestUrl varchar NOT NULL,
- userId int NOT NULL,
+ requestUrl varchar,
+ userId int,
PRIMARY KEY (requestUrl,userId),
FOREIGN KEY (requestUrl) REFERENCES requests(url) ON DELETE CASCADE,
FOREIGN KEY (userId) REFERENCES users(userId) ON DELETE CASCADE
diff --git a/db/50-bans.sql b/db/50-bans.sql
index 20ecfa1..979ae21 100644
--- a/db/50-bans.sql
+++ b/db/50-bans.sql
@@ -1,4 +1,4 @@
CREATE TABLE bans (
userid integer,
PRIMARY KEY (userid)
-);
+)
diff --git a/db/50-follows.sql b/db/50-follows.sql
deleted file mode 100644
index 63e1200..0000000
--- a/db/50-follows.sql
+++ /dev/null
@@ -1,4 +0,0 @@
-CREATE TABLE follows (
- userid integer,
- PRIMARY KEY (userid)
-);
diff --git a/db/50-subscriptions.sql b/db/50-subscriptions.sql
deleted file mode 100644
index 7e23cf1..0000000
--- a/db/50-subscriptions.sql
+++ /dev/null
@@ -1,4 +0,0 @@
-CREATE TABLE subscriptions (
- userid integer,
- PRIMARY KEY (userid)
-);
diff --git a/db/90-views.sql b/db/90-views.sql
index a31ec16..e274069 100644
--- a/db/90-views.sql
+++ b/db/90-views.sql
@@ -2,7 +2,8 @@ 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;
+ JOIN users ON requests.requester = users.userid
+ ORDER BY score DESC, reqTimestamp ASC;
CREATE OR REPLACE FUNCTION get_requests_voted(votinguserid int)
RETURNS TABLE (
@@ -20,7 +21,8 @@ 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);
+ LEFT JOIN votes ON (requests_vw.url = votes.requesturl AND votes.userid = votinguserid)
+ ORDER BY score DESC, reqTimestamp ASC;
$$;
/*
@@ -38,20 +40,18 @@ CREATE OR REPLACE VIEW vote_score_vw AS
COUNT(votes.requesturl) AS count,
COALESCE(
SUM(CASE
- WHEN follows.userid IS NULL AND subscriptions.userid IS NULL
- AND votes.userid IS NOT NULL
+ WHEN users.isfollower = FALSE AND users.issubscriber = FALSE
THEN votepoints.normaluservotepoints
- WHEN follows.userid IS NOT NULL AND subscriptions.userid IS NULL
+ WHEN users.isfollower = TRUE AND users.issubscriber = FALSE
THEN votepoints.followervotepoints
- WHEN subscriptions.userid IS NOT NULL
+ WHEN users.issubscriber = TRUE
THEN votepoints.subscribervotepoints
END), 0
) AS votescore
FROM requests
LEFT JOIN votes ON votes.requesturl = requests.url
- LEFT JOIN bans ON votes.userid = bans.userid
- LEFT JOIN follows ON votes.userid = follows.userid
- LEFT JOIN subscriptions ON votes.userid = subscriptions.userid
+ LEFT JOIN users on votes.userid = users.userid
+ LEFT JOIN bans ON users.userid = bans.userid
CROSS JOIN votepoints
WHERE bans.userid IS NULL
GROUP BY url;
@@ -60,22 +60,3 @@ CREATE OR REPLACE VIEW streamer_user_vw AS
SELECT users.userid as userid, users.displayname as displayname, users.imageurl as imageurl FROM streamer
LEFT JOIN users
ON streamer.userid = users.userid;
-
-CREATE OR REPLACE VIEW ratelimit_vw AS
- SELECT users.userid,COALESCE(count,0),ratelimit.reqcount AS max,COALESCE(count,0) >= ratelimit.reqcount AS status
- FROM users
- LEFT JOIN (SELECT requester,COUNT(url)
- FROM requests
- WHERE reqtimestamp > (now() - '24 hours'::interval)
- GROUP BY requests.requester
- ) AS requests ON users.userid = requests.requester
- LEFT JOIN follows ON requests.requester = follows.userid
- LEFT JOIN subscriptions ON requests.requester = subscriptions.userid
- CROSS JOIN config
- CROSS JOIN LATERAL (VALUES (
- CASE
- WHEN follows.userid IS NULL AND subscriptions.userid IS NULL THEN config.normaluserratelimit
- WHEN follows.userid IS NOT NULL AND subscriptions.userid IS NULL THEN config.followerratelimit
- WHEN subscriptions.userid IS NOT NULL THEN config.subscriberratelimit
- END
- )) AS ratelimit(reqcount);
diff --git a/db/95-procedures.sql b/db/95-procedures.sql
index 650f119..f2427bf 100644
--- a/db/95-procedures.sql
+++ b/db/95-procedures.sql
@@ -16,13 +16,6 @@ CREATE OR REPLACE PROCEDURE add_request(url varchar,requester int)
CALL update_scores();
$$;
-CREATE OR REPLACE PROCEDURE clear_zero_votes()
- LANGUAGE SQL
- AS $$
- DELETE FROM requests WHERE NOT EXISTS
- (SELECT FROM votes WHERE requests.url = votes.requesturl);
- $$;
-
CREATE OR REPLACE PROCEDURE add_vote(url varchar,voteuser int)
LANGUAGE SQL
AS $$
@@ -35,7 +28,6 @@ CREATE OR REPLACE PROCEDURE delete_vote(url varchar,voteuser int)
AS $$
DELETE FROM votes WHERE requesturl = url AND userid = voteuser;
CALL update_scores();
- CALL clear_zero_votes();
$$;
CREATE OR REPLACE PROCEDURE update_request_score_modifier(updateurl varchar, scoreDiff int)
@@ -44,11 +36,3 @@ CREATE OR REPLACE PROCEDURE update_request_score_modifier(updateurl varchar, sco
UPDATE scores SET scoreModifier = scoreModifier + scoreDiff WHERE url = updateurl;
CALL update_scores();
$$;
-
-CREATE OR REPLACE PROCEDURE update_vote_points(normaluser int, follower int, subscriber int)
- LANGUAGE SQL
- AS $$
- UPDATE config SET normaluservotepoints = normaluser,
- followervotepoints = follower, subscribervotepoints = subscriber;
- CALL update_scores();
- $$;
diff --git a/db/testdata.sql b/db/testdata.sql
index 98db264..83428e6 100644
--- a/db/testdata.sql
+++ b/db/testdata.sql
@@ -1,16 +1,8 @@
-INSERT INTO users (userid,displayName) VALUES
- (001,'TestUser'),
- (002,'TestFollower'),
- (003,'TestSubscriber'),
- (004,'TestSubNonFollower');
-
-INSERT INTO follows (userid) VALUES
- (002),
- (003);
-
-INSERT INTO subscriptions (userid) VALUES
- (003),
- (004);
+INSERT INTO users (userid,displayName,isFollower,isSubscriber) VALUES
+ (001,'TestUser',false,false),
+ (002,'TestFollower',true,false),
+ (003,'TestSubscriber',true,true),
+ (004,'TestSubNonFollower',false,true);
CALL add_request('https://www.youtube.com/watch?v=dQw4w9WgXcQ',001);
CALL add_request('https://www.youtube.com/watch?v=C5oeWHngDS4',002);
diff --git a/db/upgrade/v0.4-0.5.sql b/db/upgrade/v0.4-0.5.sql
deleted file mode 100644
index df6d8e7..0000000
--- a/db/upgrade/v0.4-0.5.sql
+++ /dev/null
@@ -1,53 +0,0 @@
-BEGIN;
-
-UPDATE version SET minor = 5;
-
-CREATE OR REPLACE PROCEDURE update_vote_points(normaluser int, follower int, subscriber int)
- LANGUAGE SQL
- AS $$
- UPDATE config SET normaluservotepoints = normaluser,
- followervotepoints = follower, subscribervotepoints = subscriber;
- CALL update_scores();
- $$;
-
-CREATE TABLE follows (
- userid integer,
- PRIMARY KEY (userid)
-);
-
-CREATE TABLE subscriptions (
- userid integer,
- PRIMARY KEY (userid)
-);
-
-CREATE OR REPLACE VIEW vote_score_vw AS
- WITH votepoints AS (SELECT normaluservotepoints, followervotepoints, subscribervotepoints FROM config)
- SELECT requests.url AS url,
- COUNT(votes.requesturl) AS count,
- COALESCE(
- SUM(CASE
- WHEN follows.userid IS NULL AND subscriptions.userid IS NULL
- AND votes.userid IS NOT NULL
- THEN votepoints.normaluservotepoints
- WHEN follows.userid IS NOT NULL AND subscriptions.userid IS NULL
- THEN votepoints.followervotepoints
- WHEN subscriptions.userid IS NOT NULL
- THEN votepoints.subscribervotepoints
- END), 0
- ) AS votescore
- FROM requests
- LEFT JOIN votes ON votes.requesturl = requests.url
- LEFT JOIN bans ON votes.userid = bans.userid
- LEFT JOIN follows ON votes.userid = follows.userid
- LEFT JOIN subscriptions ON votes.userid = subscriptions.userid
- CROSS JOIN votepoints
- WHERE bans.userid IS NULL
- GROUP BY url;
-
-ALTER TABLE users DROP COLUMN isfollower, DROP COLUMN issubscriber;
-
-INSERT INTO cron (jobName,runInterval) VALUES
-('processFollows','30 minutes'),
-('processSubscriptions','30 minutes');
-
-COMMIT;
diff --git a/db/upgrade/v0.5-v0.6.sql b/db/upgrade/v0.5-v0.6.sql
deleted file mode 100644
index a43869c..0000000
--- a/db/upgrade/v0.5-v0.6.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-BEGIN;
-
-UPDATE version SET minor = 6;
-
-COMMIT;
diff --git a/db/upgrade/v0.6-v0.7.sql b/db/upgrade/v0.6-v0.7.sql
deleted file mode 100644
index 0939227..0000000
--- a/db/upgrade/v0.6-v0.7.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-BEGIN;
-
-UPDATE version SET minor = 7;
-
-ALTER TABLE votes
- ALTER COLUMN requestUrl SET NOT NULL,
- ALTER COLUMN userId SET NOT NULL;
-
-CREATE OR REPLACE PROCEDURE clear_zero_votes()
- LANGUAGE SQL
- AS $$
- DELETE FROM requests WHERE NOT EXISTS
- (SELECT FROM votes WHERE requests.url = votes.requesturl);
- $$;
-
-CREATE OR REPLACE PROCEDURE delete_vote(url varchar,voteuser int)
- LANGUAGE SQL
- AS $$
- DELETE FROM votes WHERE requesturl = url AND userid = voteuser;
- CALL update_scores();
- CALL clear_zero_votes();
- $$;
-
-COMMIT;
diff --git a/db/upgrade/v0.7-v0.8.sql b/db/upgrade/v0.7-v0.8.sql
deleted file mode 100644
index af83dae..0000000
--- a/db/upgrade/v0.7-v0.8.sql
+++ /dev/null
@@ -1,35 +0,0 @@
-BEGIN;
-
-UPDATE version SET minor = 8;
-
-ALTER TABLE config
- ALTER COLUMN normaluservotepoints SET DEFAULT 10,
- ALTER COLUMN followervotepoints SET DEFAULT 50,
- ALTER COLUMN subscribervotepoints SET DEFAULT 100,
- ALTER COLUMN title SET DEFAULT '{username}''s Learn Request Queue',
- ALTER COLUMN colors SET DEFAULT '{"bg": {"primary": "#444444","table": "#282828","navbar": "#666666","error": "#ff0000"},"fg": {"primary": "#dddddd","ahover": "#ffffff","title": "#eeeeee"}}',
- ADD COLUMN normaluserratelimit int NOT NULL DEFAULT 1,
- ADD COLUMN followerratelimit int NOT NULL DEFAULT 2,
- ADD COLUMN subscriberratelimit int NOT NULL DEFAULT 3;
-
-CREATE OR REPLACE VIEW ratelimit_vw AS
- SELECT users.userid,COALESCE(count,0),ratelimit.reqcount AS max,COALESCE(count,0) >= ratelimit.reqcount AS status
- FROM users
- LEFT JOIN (SELECT requester,COUNT(url)
- FROM requests
- WHERE reqtimestamp > (now() - '24 hours'::interval)
- GROUP BY requests.requester
- ) AS requests ON users.userid = requests.requester
- LEFT JOIN follows ON requests.requester = follows.userid
- LEFT JOIN subscriptions ON requests.requester = subscriptions.userid
- CROSS JOIN config
- CROSS JOIN LATERAL (VALUES (
- CASE
- WHEN follows.userid IS NULL AND subscriptions.userid IS NULL THEN config.normaluserratelimit
- WHEN follows.userid IS NOT NULL AND subscriptions.userid IS NULL THEN config.followerratelimit
- WHEN subscriptions.userid IS NOT NULL THEN config.subscriberratelimit
- END
- )) AS ratelimit(reqcount);
-
-
-COMMIT;
diff --git a/public/main.js b/public/main.js
index e9fee5d..48d4a06 100644
--- a/public/main.js
+++ b/public/main.js
@@ -1,52 +1,29 @@
var requestsDiv = document.getElementById("requests");
-var cronJobs = ['processBans'];
-var currentPage = 1;
-var totalPages = 1;
-var count = document.getElementById("count").value;
-var sortBy = document.getElementById("sortBy").value;
-var sortDir = "desc";
+var cronJobs = ['processBans']
-function getRequests(offset,allRequests) {
- if (allRequests) var reqUrl = "/api/getAllRequests";
- else var reqUrl = "/api/getRequests";
- reqUrl += `?count=${count}&offset=${offset}&sort=${sortBy}&sortDirection=${sortDir}`;
+function getRequests(count,allRequests) {
+ var reqUrl;
+ if (allRequests) {
+ reqUrl = "/api/getAllRequests";
+ } else {
+ reqUrl = "/api/getRequests";
+ }
+ reqUrl += `?count=${count}`;
fetch(reqUrl)
.then(response => response.json())
.then(requests => {
- buildTable(requests);
+ window.requests = requests;
+ buildTable();
});
}
-function buildTable(requests) {
- totalPages = Math.ceil(requests.total/document.getElementById("count").value);
- document.getElementById("totalPages").innerText = totalPages;
- if (currentPage <= 1) {
- currentPage = 1;
- document.getElementById("pageBtnFirst").disabled = true;
- document.getElementById("pageBtnPrev").disabled = true;
- } else {
- document.getElementById("pageBtnFirst").disabled = false;
- document.getElementById("pageBtnPrev").disabled = false;
- }
- if (currentPage >= totalPages) {
- currentPage = totalPages;
- document.getElementById("pageBtnLast").disabled = true;
- document.getElementById("pageBtnNext").disabled = true;
- } else {
- document.getElementById("pageBtnLast").disabled = false;
- document.getElementById("pageBtnNext").disabled = false;
- }
- document.getElementById("page").innerHTML = "";
- for (i = 1; i <= totalPages; i++) {
- document.getElementById("page").innerHTML += ``;
- }
- document.getElementById("page").value = currentPage;
- var requestsDivHTML = '
Song Title
Requester
Score
';
+function buildTable() {
+ var requestsDivHTML = '
Song
Requester
Score
';
requestsDivHTML += '
State';
if (window.loggedIn) requestsDivHTML += '
Vote';
if (window.isStreamer) requestsDivHTML += '
Update
'
requestsDivHTML += "
";
- for (request of requests.requests) {
+ for (request of requests) {
requestsDivHTML += `