mirror of
https://github.com/sigmasternchen/mobmash.click
synced 2025-03-16 00:29:05 +00:00
fix: Trends now not only depend on the history cache but also the current history
closes #1
This commit is contained in:
parent
26b31718bd
commit
b6921bcb52
1 changed files with 33 additions and 0 deletions
33
migrations/0002_fixTrendsFromCacheAndCurrent.sql
Normal file
33
migrations/0002_fixTrendsFromCacheAndCurrent.sql
Normal file
|
@ -0,0 +1,33 @@
|
|||
CREATE OR REPLACE VIEW mm_rating_trends (mob, rating, "date", id) AS
|
||||
WITH complete_history (ratings, last_update) AS (
|
||||
SELECT * FROM mm_history_cache
|
||||
UNION SELECT * FROM mm_rating_history
|
||||
)
|
||||
SELECT
|
||||
cast(key AS numeric) AS mob,
|
||||
cast(value AS numeric) rating,
|
||||
"date",
|
||||
id
|
||||
FROM (
|
||||
SELECT
|
||||
id,
|
||||
ratings,
|
||||
"date"
|
||||
FROM (
|
||||
SELECT
|
||||
max(id) AS id,
|
||||
"date"
|
||||
FROM (
|
||||
SELECT
|
||||
last_update AS id,
|
||||
date(matches.created) AS "date"
|
||||
FROM complete_history AS history
|
||||
INNER JOIN mm_matches AS matches
|
||||
ON history.last_update = matches.id
|
||||
) AS dates
|
||||
GROUP BY "date"
|
||||
) AS key_dates
|
||||
INNER JOIN complete_history AS history
|
||||
ON key_dates.id = history.last_update
|
||||
) AS ratings_at_key_date,
|
||||
jsonb_each(ratings_at_key_date.ratings) AS ratings(key, value);
|
Loading…
Reference in a new issue