Skip to content
Snippets Groups Projects

Draft: refactor follows and update_nofications indexing

Open Dan Notestein requested to merge 267-update-notification-cache into develop
Files
4
@@ -96,19 +96,6 @@ CREATE OR REPLACE VIEW hivemind_app.hive_raw_notifications_as_view
notifs.payload,
harv.score
FROM (
SELECT hr.block_num,
hp.id AS post_id,
14 AS type_id,
hr.created_at,
hr.blogger_id AS src,
hp.author_id AS dst,
hr.post_id as dst_post_id,
''::character varying(16) AS community,
''::character varying AS community_title,
''::character varying AS payload
FROM hivemind_app.hive_reblogs hr -- reblogs
JOIN hivemind_app.hive_posts hp ON hr.post_id = hp.id
UNION ALL
SELECT hs.block_num,
0 AS post_id,
11 AS type_id,
@@ -230,25 +217,3 @@ FROM
SELECT * FROM hivemind_app.hive_raw_notifications_view_no_account_score
) as notifs
WHERE notifs.score >= 0 AND notifs.src IS DISTINCT FROM notifs.dst;
DROP VIEW IF EXISTS hivemind_app.notifications_scores CASCADE;
CREATE OR REPLACE VIEW hivemind_app.notifications_scores AS
-- With clause is inlined, modified call to reptracker_endpoints.get_account_reputation.
-- Reputation is multiplied by 7.5 rather than 9 to bring the max value to 100 rather than 115.
-- In case of reputation being 0, the score is set to 25 rather than 0.
WITH log_account_rep AS
(
SELECT
account_id,
LOG(10, ABS(nullif(reputation, 0))) AS rep,
(CASE WHEN reputation < 0 THEN -1 ELSE 1 END) AS is_neg
FROM reptracker_app.account_reputations
),
calculate_rep AS
(
SELECT
account_id,
GREATEST(lar.rep - 9, 0) * lar.is_neg AS rep
FROM log_account_rep lar
)
SELECT account_id, COALESCE((cr.rep * 7.5 + 25)::INT, 25) AS score FROM calculate_rep AS cr
Loading