2021-02-23 06:54:47 +00:00
|
|
|
BEGIN;
|
|
|
|
|
2021-02-25 03:15:16 +00:00
|
|
|
UPDATE version SET minor = 5;
|
2021-02-23 06:54:47 +00:00
|
|
|
|
|
|
|
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
|
2021-02-25 02:56:39 +00:00
|
|
|
AND votes.userid IS NOT NULL
|
2021-02-23 06:54:47 +00:00
|
|
|
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
|
2021-02-25 02:56:39 +00:00
|
|
|
LEFT JOIN bans ON votes.userid = bans.userid
|
|
|
|
LEFT JOIN follows ON votes.userid = follows.userid
|
|
|
|
LEFT JOIN subscriptions ON votes.userid = subscriptions.userid
|
2021-02-23 06:54:47 +00:00
|
|
|
CROSS JOIN votepoints
|
|
|
|
WHERE bans.userid IS NULL
|
|
|
|
GROUP BY url;
|
|
|
|
|
|
|
|
ALTER TABLE users DROP COLUMN isfollower, DROP COLUMN issubscriber;
|
|
|
|
|
2021-02-25 02:40:58 +00:00
|
|
|
INSERT INTO cron (jobName,runInterval) VALUES
|
|
|
|
('processFollows','30 minutes'),
|
|
|
|
('processSubscriptions','30 minutes');
|
|
|
|
|
2021-02-23 06:54:47 +00:00
|
|
|
COMMIT;
|