From e388214f7e8b435669be878e085071f812de6dd3 Mon Sep 17 00:00:00 2001 From: harisato Date: Wed, 26 Jul 2023 16:41:39 +0700 Subject: [PATCH] feat(hasura): sort by latest chapter publish --- .../punkga-pg/tables/public_manga.yaml | 6 ++ hasura/metadata/query_collections.yaml | 91 ++++++++++--------- .../down.sql | 11 +++ .../up.sql | 9 ++ 4 files changed, 73 insertions(+), 44 deletions(-) create mode 100644 hasura/migrations/punkga-pg/1690364416444_create manga latest publish function/down.sql create mode 100644 hasura/migrations/punkga-pg/1690364416444_create manga latest publish function/up.sql diff --git a/hasura/metadata/databases/punkga-pg/tables/public_manga.yaml b/hasura/metadata/databases/punkga-pg/tables/public_manga.yaml index 23185829..d17159c5 100644 --- a/hasura/metadata/databases/punkga-pg/tables/public_manga.yaml +++ b/hasura/metadata/databases/punkga-pg/tables/public_manga.yaml @@ -70,6 +70,12 @@ array_relationships: table: name: social_activities schema: public +computed_fields: + - name: latest_published + definition: + function: + name: latest_published + schema: public select_permissions: - role: anonymous permission: diff --git a/hasura/metadata/query_collections.yaml b/hasura/metadata/query_collections.yaml index b3b23c00..aec53a62 100644 --- a/hasura/metadata/query_collections.yaml +++ b/hasura/metadata/query_collections.yaml @@ -457,50 +457,6 @@ } } } - - name: Public - Query latest update manga - query: | - query GetLatestUpdatedManga { - manga(order_by: {chapters_aggregate:{min:{updated_at:desc_nulls_last}}}, limit: 6, where: {status:{_neq:"Removed"}}) { - id - manga_total_views { - views - } - manga_total_likes { - likes - } - manga_creators { - creator { - id - name - isActive - } - } - status - chapters(limit: 1, order_by: {updated_at:desc}, where: {status:{_eq:"Published"}}) { - id - chapter_number - updated_at - } - manga_tags { - tag { - id - tag_languages { - language_id - tag_id - value - } - } - } - manga_languages { - title - description - is_main_language - language_id - } - banner - poster - } - } - name: Public - Get subscribe list query: | query GetSubscribeList ($user_id: String = "") { @@ -836,3 +792,50 @@ } } } + - name: Public - Query latest update manga + query: | + query GetLatestUpdatedManga { + manga(order_by: {latest_published:desc_nulls_last}, limit: 6, where: {status:{_neq:"Removed"}}) { + id + latest_published + manga_total_views { + views + } + manga_total_likes { + likes + } + manga_creators { + creator { + id + name + isActive + } + } + status + chapters(limit: 1, order_by: {pushlish_date:desc}, where: {status:{_eq:"Published"}}) { + id + chapter_number + pushlish_date + status + updated_at + } + manga_tags { + tag { + id + tag_languages { + language_id + tag_id + value + } + } + } + manga_languages { + title + description + is_main_language + language_id + } + banner + poster + } + } diff --git a/hasura/migrations/punkga-pg/1690364416444_create manga latest publish function/down.sql b/hasura/migrations/punkga-pg/1690364416444_create manga latest publish function/down.sql new file mode 100644 index 00000000..96d35ba4 --- /dev/null +++ b/hasura/migrations/punkga-pg/1690364416444_create manga latest publish function/down.sql @@ -0,0 +1,11 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- CREATE OR REPLACE FUNCTION latest_published(manga_row manga) RETURNS +-- timestamp with time zone +-- AS $$ +-- SELECT pushlish_date +-- FROM chapters +-- WHERE chapters.manga_id = manga_row.id AND chapters.status = 'Published' +-- ORDER BY pushlish_date DESC NULLS LAST +-- LIMIT 1 +-- $$ LANGUAGE sql STABLE; diff --git a/hasura/migrations/punkga-pg/1690364416444_create manga latest publish function/up.sql b/hasura/migrations/punkga-pg/1690364416444_create manga latest publish function/up.sql new file mode 100644 index 00000000..5bad5446 --- /dev/null +++ b/hasura/migrations/punkga-pg/1690364416444_create manga latest publish function/up.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE FUNCTION latest_published(manga_row manga) RETURNS +timestamp with time zone +AS $$ + SELECT pushlish_date + FROM chapters + WHERE chapters.manga_id = manga_row.id AND chapters.status = 'Published' + ORDER BY pushlish_date DESC NULLS LAST + LIMIT 1 +$$ LANGUAGE sql STABLE;