feat(*.php, *.psql): deduplicate API code + performance improvements
This commit is contained in:
parent
cf3dac8a46
commit
4bad005e58
31 changed files with 502 additions and 666 deletions
|
@ -1,6 +1,7 @@
|
|||
CREATE OR REPLACE VIEW optimized_recent_activity AS
|
||||
WITH activity_data AS (
|
||||
SELECT
|
||||
NULL::bigint AS id,
|
||||
p.date AS content_date,
|
||||
p.title,
|
||||
p.content AS description,
|
||||
|
@ -22,6 +23,7 @@ WITH activity_data AS (
|
|||
UNION ALL
|
||||
|
||||
SELECT
|
||||
NULL::bigint AS id,
|
||||
l.date AS content_date,
|
||||
l.title,
|
||||
l.description,
|
||||
|
@ -43,6 +45,7 @@ WITH activity_data AS (
|
|||
UNION ALL
|
||||
|
||||
SELECT
|
||||
NULL::bigint AS id,
|
||||
b.date_finished AS content_date,
|
||||
CONCAT(b.title,
|
||||
CASE WHEN b.rating IS NOT NULL THEN CONCAT(' (', b.rating, ')') ELSE '' END
|
||||
|
@ -67,6 +70,7 @@ WITH activity_data AS (
|
|||
UNION ALL
|
||||
|
||||
SELECT
|
||||
NULL::bigint AS id,
|
||||
m.last_watched AS content_date,
|
||||
CONCAT(m.title,
|
||||
CASE WHEN m.rating IS NOT NULL THEN CONCAT(' (', m.rating, ')') ELSE '' END
|
||||
|
@ -91,6 +95,7 @@ WITH activity_data AS (
|
|||
UNION ALL
|
||||
|
||||
SELECT
|
||||
c.id,
|
||||
c.date AS content_date,
|
||||
CONCAT(c.artist->>'name', ' at ', c.venue->>'name_short') AS title,
|
||||
c.concert_notes AS description,
|
||||
|
@ -104,7 +109,7 @@ WITH activity_data AS (
|
|||
c.venue->>'latitude' AS venue_lat,
|
||||
c.venue->>'longitude' AS venue_lon,
|
||||
c.venue->>'name_short' AS venue_name,
|
||||
c.notes AS notes,
|
||||
c.concert_notes AS notes,
|
||||
'concerts' AS type,
|
||||
'Concert' AS label
|
||||
FROM optimized_concerts c
|
||||
|
|
|
@ -2,7 +2,6 @@ CREATE OR REPLACE VIEW optimized_concerts AS
|
|||
SELECT
|
||||
c.id,
|
||||
c.date,
|
||||
c.notes,
|
||||
CASE WHEN c.artist IS NOT NULL THEN
|
||||
json_build_object('name', a.name_string, 'url', a.slug)
|
||||
ELSE
|
||||
|
@ -16,4 +15,3 @@ FROM
|
|||
LEFT JOIN venues v ON c.venue = v.id
|
||||
ORDER BY
|
||||
c.date DESC;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue