Skip to content

Commit

Permalink
feat(hasura): sort by latest chapter publish
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Jul 26, 2023
1 parent 0c45ce0 commit e388214
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 44 deletions.
6 changes: 6 additions & 0 deletions hasura/metadata/databases/punkga-pg/tables/public_manga.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
91 changes: 47 additions & 44 deletions hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "") {
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e388214

Please sign in to comment.