diff --git a/happyview-modules/lua/endpoints/getFollow.lua b/happyview-modules/lua/endpoints/getFollow.lua index 44d5aebf..b2b5c32d 100644 --- a/happyview-modules/lua/endpoints/getFollow.lua +++ b/happyview-modules/lua/endpoints/getFollow.lua @@ -55,15 +55,23 @@ local function account_follow_filter_sql() return "NOT COALESCE(starts_with(record::jsonb->'via'->>'uri', 'at://' || (record::jsonb->>'subject') || '/org.hypercerts.collection/'), FALSE)" end -local FOLLOW = "app.certified.graph.follow" +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" --- Guard the cast inside CASE; a WHERE filter cannot protect it from planner reordering. -local function follow_sort_key() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" end +local FOLLOW = "app.certified.graph.follow" + local function query(sql, values) if db.backend() ~= "postgres" then error("ActorFollowQueryFailed: actor-follow queries require PostgreSQL", 0) end local ok, result = pcall(db.raw, sql, values) @@ -73,7 +81,7 @@ end local function query_follow(actor, subject) local rows = query( - "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record FROM happyview_records CROSS JOIN LATERAL (SELECT " .. follow_sort_key() .. " AS sort_at) sorted WHERE collection = $1 AND did = $2 AND record::jsonb->>'subject' = $3 AND " .. account_follow_filter_sql() .. " ORDER BY sorted.sort_at ASC, uri ASC LIMIT 1", + "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record FROM happyview_records CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted WHERE collection = $1 AND did = $2 AND record::jsonb->>'subject' = $3 AND " .. account_follow_filter_sql() .. " ORDER BY sorted.sort_at ASC, uri ASC LIMIT 1", { FOLLOW, actor, subject }) if #rows == 0 then return NULL end return record_view(rows[1]) diff --git a/happyview-modules/lua/endpoints/getFollows.lua b/happyview-modules/lua/endpoints/getFollows.lua index 44080535..11851d35 100644 --- a/happyview-modules/lua/endpoints/getFollows.lua +++ b/happyview-modules/lua/endpoints/getFollows.lua @@ -55,15 +55,23 @@ local function account_follow_filter_sql() return "NOT COALESCE(starts_with(record::jsonb->'via'->>'uri', 'at://' || (record::jsonb->>'subject') || '/org.hypercerts.collection/'), FALSE)" end -local FOLLOW = "app.certified.graph.follow" - --- Guard the cast inside CASE; a WHERE filter cannot protect it from planner reordering. -local function follow_sort_key() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" + +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" end +local FOLLOW = "app.certified.graph.follow" + local function query(sql, values) if db.backend() ~= "postgres" then error("ActorFollowQueryFailed: actor-follow queries require PostgreSQL", 0) end local ok, result = pcall(db.raw, sql, values) @@ -174,7 +182,7 @@ local function get_follows() .. "SELECT DISTINCT ON (requested.target) requested.target AS target, uri, did, cid, " .. "indexed_at::text AS indexed_at, record::text AS record FROM requested " .. "JOIN happyview_records ON collection = $1 AND did = $2 AND record::jsonb->>'subject' = requested.target AND " .. account_follow_filter_sql() .. " " - .. "CROSS JOIN LATERAL (SELECT " .. follow_sort_key() .. " AS sort_at) sorted " + .. "CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted " .. "ORDER BY requested.target, sorted.sort_at ASC, uri ASC", values) if type(rows) ~= "table" then error("ActorFollowQueryFailed: actor-follow lookup failed", 0) end diff --git a/happyview-modules/lua/endpoints/listActorFollowers.lua b/happyview-modules/lua/endpoints/listActorFollowers.lua index 55d3af98..ccd58823 100644 --- a/happyview-modules/lua/endpoints/listActorFollowers.lua +++ b/happyview-modules/lua/endpoints/listActorFollowers.lua @@ -140,15 +140,23 @@ local function account_follow_filter_sql() return "NOT COALESCE(starts_with(record::jsonb->'via'->>'uri', 'at://' || (record::jsonb->>'subject') || '/org.hypercerts.collection/'), FALSE)" end -local FOLLOW = "app.certified.graph.follow" +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" --- Guard the cast inside CASE; a WHERE filter cannot protect it from planner reordering. -local function follow_sort_key() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" end +local FOLLOW = "app.certified.graph.follow" + local function query(sql, values) if db.backend() ~= "postgres" then error("ActorFollowQueryFailed: actor-follow queries require PostgreSQL", 0) end local ok, result = pcall(db.raw, sql, values) @@ -199,7 +207,7 @@ local function build_actor_follow_query(mode, actor, limit, cursor, direction) values[#values + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" local displayed_did = mode == "followers" and "did" or "subject_did" - local sql = "WITH ranked_follows AS (SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, record::jsonb->>'subject' AS subject_did, sorted.sort_at, ROW_NUMBER() OVER (PARTITION BY did, record::jsonb->>'subject' ORDER BY sorted.sort_at ASC, uri ASC) AS relationship_rank FROM happyview_records CROSS JOIN LATERAL (SELECT " .. follow_sort_key() .. " AS sort_at) sorted WHERE " .. table.concat(filters, " AND ") .. "), representatives AS (SELECT uri, did, cid, indexed_at, record, sort_at, " .. displayed_did .. " AS actor_did FROM ranked_follows WHERE relationship_rank = 1), " .. + local sql = "WITH ranked_follows AS (SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, record::jsonb->>'subject' AS subject_did, sorted.sort_at, ROW_NUMBER() OVER (PARTITION BY did, record::jsonb->>'subject' ORDER BY sorted.sort_at ASC, uri ASC) AS relationship_rank FROM happyview_records CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted WHERE " .. table.concat(filters, " AND ") .. "), representatives AS (SELECT uri, did, cid, indexed_at, record, sort_at, " .. displayed_did .. " AS actor_did FROM ranked_follows WHERE relationship_rank = 1), " .. "total AS (SELECT COUNT(*) AS total_count FROM representatives), " .. "page AS (SELECT uri, did, cid, indexed_at, record, sort_at, actor_did FROM representatives" .. cursor_filter .. " ORDER BY sort_at " .. ordering .. ", uri " .. ordering .. " LIMIT $" .. #values .. ") " .. "SELECT page.uri, page.did, page.cid, page.indexed_at, page.record, page.actor_did, total.total_count, to_char(page.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp FROM total LEFT JOIN page ON TRUE ORDER BY page.sort_at " .. ordering .. ", page.uri " .. ordering diff --git a/happyview-modules/lua/endpoints/listActorFollowing.lua b/happyview-modules/lua/endpoints/listActorFollowing.lua index 0f40eb93..5ca40982 100644 --- a/happyview-modules/lua/endpoints/listActorFollowing.lua +++ b/happyview-modules/lua/endpoints/listActorFollowing.lua @@ -140,15 +140,23 @@ local function account_follow_filter_sql() return "NOT COALESCE(starts_with(record::jsonb->'via'->>'uri', 'at://' || (record::jsonb->>'subject') || '/org.hypercerts.collection/'), FALSE)" end -local FOLLOW = "app.certified.graph.follow" +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" --- Guard the cast inside CASE; a WHERE filter cannot protect it from planner reordering. -local function follow_sort_key() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" end +local FOLLOW = "app.certified.graph.follow" + local function query(sql, values) if db.backend() ~= "postgres" then error("ActorFollowQueryFailed: actor-follow queries require PostgreSQL", 0) end local ok, result = pcall(db.raw, sql, values) @@ -199,7 +207,7 @@ local function build_actor_follow_query(mode, actor, limit, cursor, direction) values[#values + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" local displayed_did = mode == "followers" and "did" or "subject_did" - local sql = "WITH ranked_follows AS (SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, record::jsonb->>'subject' AS subject_did, sorted.sort_at, ROW_NUMBER() OVER (PARTITION BY did, record::jsonb->>'subject' ORDER BY sorted.sort_at ASC, uri ASC) AS relationship_rank FROM happyview_records CROSS JOIN LATERAL (SELECT " .. follow_sort_key() .. " AS sort_at) sorted WHERE " .. table.concat(filters, " AND ") .. "), representatives AS (SELECT uri, did, cid, indexed_at, record, sort_at, " .. displayed_did .. " AS actor_did FROM ranked_follows WHERE relationship_rank = 1), " .. + local sql = "WITH ranked_follows AS (SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, record::jsonb->>'subject' AS subject_did, sorted.sort_at, ROW_NUMBER() OVER (PARTITION BY did, record::jsonb->>'subject' ORDER BY sorted.sort_at ASC, uri ASC) AS relationship_rank FROM happyview_records CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted WHERE " .. table.concat(filters, " AND ") .. "), representatives AS (SELECT uri, did, cid, indexed_at, record, sort_at, " .. displayed_did .. " AS actor_did FROM ranked_follows WHERE relationship_rank = 1), " .. "total AS (SELECT COUNT(*) AS total_count FROM representatives), " .. "page AS (SELECT uri, did, cid, indexed_at, record, sort_at, actor_did FROM representatives" .. cursor_filter .. " ORDER BY sort_at " .. ordering .. ", uri " .. ordering .. " LIMIT $" .. #values .. ") " .. "SELECT page.uri, page.did, page.cid, page.indexed_at, page.record, page.actor_did, total.total_count, to_char(page.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp FROM total LEFT JOIN page ON TRUE ORDER BY page.sort_at " .. ordering .. ", page.uri " .. ordering diff --git a/happyview-modules/lua/endpoints/listBadgeAwards.lua b/happyview-modules/lua/endpoints/listBadgeAwards.lua index d67c1379..d57d0cb9 100644 --- a/happyview-modules/lua/endpoints/listBadgeAwards.lua +++ b/happyview-modules/lua/endpoints/listBadgeAwards.lua @@ -82,6 +82,21 @@ local function cursor_encode(value) return (encoded:gsub(".", function(char) return string.format("%02x", string.byte(char)) end)) end +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" + +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" +end + local NULL = json.decode("null") local function record_view(row) @@ -277,15 +292,6 @@ local function decode_badge_award_cursor(token, direction) return value end -local function award_sort_expression() - local created = "award.record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(award.record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE " .. - "COALESCE(award.indexed_at::timestamptz, award.created_at::timestamptz) END" -end - local function recipient_did_expression() local subject = "award.record::jsonb->'subject'" return "CASE WHEN jsonb_typeof(" .. subject .. ") = 'string' THEN award.record::jsonb->>'subject' " .. @@ -382,7 +388,7 @@ local function list_badge_awards(authors, badge_uris, badge_types, subjects, res "recipient_response.uri AS recipient_response_uri, recipient_response.cid AS recipient_response_cid, " .. "recipient_response.indexed_at::text AS recipient_response_indexed_at, " .. "recipient_response.did AS recipient_response_did, recipient_response.record::text AS recipient_response_record " .. - "FROM happyview_records AS award CROSS JOIN LATERAL (SELECT " .. award_sort_expression() .. " AS sort_at) sorted " .. + "FROM happyview_records AS award CROSS JOIN LATERAL (SELECT " .. created_at_sort("award") .. " AS sort_at) sorted " .. "LEFT JOIN happyview_records AS badge ON badge.collection = '" .. DEFINITION .. "' " .. "AND badge.uri = award.record::jsonb->'badge'->>'uri' " .. "AND badge.cid = award.record::jsonb->'badge'->>'cid' " .. diff --git a/happyview-modules/lua/endpoints/listBadgeDefinitions.lua b/happyview-modules/lua/endpoints/listBadgeDefinitions.lua index 6923f2b5..13c6383e 100644 --- a/happyview-modules/lua/endpoints/listBadgeDefinitions.lua +++ b/happyview-modules/lua/endpoints/listBadgeDefinitions.lua @@ -89,6 +89,21 @@ local function cursor_encode(value) return (encoded:gsub(".", function(char) return string.format("%02x", string.byte(char)) end)) end +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" + +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" +end + local NULL = json.decode("null") local function record_view(row) @@ -191,14 +206,6 @@ local function decode_badge_definition_cursor(token, direction) return value end -local function badge_definition_sort_expression() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" -end - local function list_badge_definitions(authors, badge_types, limit, cursor, direction) if db.backend() ~= "postgres" then error("BadgeDefinitionQueryFailed: badge definition API requires PostgreSQL", 0) @@ -216,7 +223,7 @@ local function list_badge_definitions(authors, badge_types, limit, cursor, direc end values[#values + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" - local sort_expression = badge_definition_sort_expression() + local sort_expression = created_at_sort() local sql = "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, " .. "to_char(sorted.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp " .. "FROM happyview_records CROSS JOIN LATERAL (SELECT " .. sort_expression .. " AS sort_at) sorted WHERE " .. diff --git a/happyview-modules/lua/endpoints/listBadgeResponses.lua b/happyview-modules/lua/endpoints/listBadgeResponses.lua index 536b0f61..fdf71f02 100644 --- a/happyview-modules/lua/endpoints/listBadgeResponses.lua +++ b/happyview-modules/lua/endpoints/listBadgeResponses.lua @@ -82,6 +82,21 @@ local function cursor_encode(value) return (encoded:gsub(".", function(char) return string.format("%02x", string.byte(char)) end)) end +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" + +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" +end + local NULL = json.decode("null") local function record_view(row) @@ -162,15 +177,6 @@ local function decode_badge_response_cursor(token, direction) return value end -local function response_sort_expression() - local created = "response.record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(response.record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE " .. - "COALESCE(response.indexed_at::timestamptz, response.created_at::timestamptz) END" -end - local function list_badge_responses(badge_award, limit, cursor, direction) local where, values = { "response.collection = $1" }, { RESPONSE } if badge_award then @@ -191,7 +197,7 @@ local function list_badge_responses(badge_award, limit, cursor, direction) local sql = "SELECT response.uri, response.did, response.cid, response.indexed_at::text AS indexed_at, " .. "response.record::text AS record, to_char(sorted.sort_at AT TIME ZONE 'UTC', " .. "'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp " .. - "FROM happyview_records AS response CROSS JOIN LATERAL (SELECT " .. response_sort_expression() .. " AS sort_at) sorted " .. + "FROM happyview_records AS response CROSS JOIN LATERAL (SELECT " .. created_at_sort("response") .. " AS sort_at) sorted " .. "WHERE " .. table.concat(where, " AND ") .. " ORDER BY sorted.sort_at " .. ordering .. ", response.uri " .. ordering .. " LIMIT $" .. #values local rows = query(sql, values) diff --git a/happyview-modules/lua/endpoints/listEvmLinks.lua b/happyview-modules/lua/endpoints/listEvmLinks.lua index 675c843e..cccce77b 100644 --- a/happyview-modules/lua/endpoints/listEvmLinks.lua +++ b/happyview-modules/lua/endpoints/listEvmLinks.lua @@ -82,6 +82,21 @@ local function cursor_encode(value) return (encoded:gsub(".", function(char) return string.format("%02x", string.byte(char)) end)) end +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" + +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" +end + local NULL = json.decode("null") local function record_view(row) @@ -230,16 +245,6 @@ local function decode_evm_link_cursor(token, direction) return value end -local function evm_link_sort_key() - -- CASE guards the cast from malformed publisher-controlled timestamps. - local created = "link.record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(link.record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE " .. - "COALESCE(link.indexed_at::timestamptz, link.created_at::timestamptz) END" -end - local function list_evm_links(actors, addresses, limit, cursor, direction) local where, values = { "link.collection = $1" }, { EVMLINK } add_filter(where, values, "link.did", actors) @@ -260,7 +265,7 @@ local function list_evm_links(actors, addresses, limit, cursor, direction) local sql = "SELECT link.uri, link.did, link.cid, link.indexed_at::text AS indexed_at, " .. "link.record::text AS record, to_char(sorted.sort_at AT TIME ZONE 'UTC', " .. "'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp " .. - "FROM happyview_records AS link CROSS JOIN LATERAL (SELECT " .. evm_link_sort_key() .. " AS sort_at) sorted WHERE " .. + "FROM happyview_records AS link CROSS JOIN LATERAL (SELECT " .. created_at_sort("link") .. " AS sort_at) sorted WHERE " .. table.concat(where, " AND ") .. " ORDER BY sorted.sort_at " .. ordering .. ", link.uri " .. ordering .. " LIMIT $" .. #values local rows = evm_link_query(sql, values) diff --git a/happyview-modules/lua/endpoints/listFeatures.lua b/happyview-modules/lua/endpoints/listFeatures.lua index d40a6b92..1c0b6cd8 100644 --- a/happyview-modules/lua/endpoints/listFeatures.lua +++ b/happyview-modules/lua/endpoints/listFeatures.lua @@ -82,6 +82,20 @@ local function cursor_encode(value) return (encoded:gsub(".", function(char) return string.format("%02x", string.byte(char)) end)) end +-- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. +local function add_in(where, binds, column, items) + if #items == 0 then + where[#where + 1] = "FALSE" + return + end + local marks = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + marks[#marks + 1] = "$" .. #binds + end + where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" +end + local FEATURE_COLLECTION = "org.hypercerts.entity.feature" local function feature_valid_uri(value) @@ -201,20 +215,6 @@ local function feature_array(params, key, validate, description, max_bytes) return unique end -local function feature_add_in(where, values, column, binds) - if values == nil then return end - if #values == 0 then - where[#where + 1] = "FALSE" - return - end - local placeholders = {} - for _, value in ipairs(values) do - binds[#binds + 1] = value - placeholders[#placeholders + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(placeholders, ", ") .. ")" -end - local function feature_add_types(where, values, binds) if values == nil then return end if #values == 0 then @@ -280,7 +280,7 @@ end local function feature_list_rows(filters, limit, cursor, direction) local where, binds = { "feature.collection = $1" }, { FEATURE_COLLECTION } - feature_add_in(where, filters.authors, "feature.did", binds) + if filters.authors then add_in(where, binds, "feature.did", filters.authors) end feature_add_types(where, filters.types, binds) if filters.hasOrganizationRecord ~= nil then local predicate = filters.hasOrganizationRecord and "EXISTS" or "NOT EXISTS" diff --git a/happyview-modules/lua/endpoints/listLocations.lua b/happyview-modules/lua/endpoints/listLocations.lua index 4e9d8d1b..b1921f7d 100644 --- a/happyview-modules/lua/endpoints/listLocations.lua +++ b/happyview-modules/lua/endpoints/listLocations.lua @@ -82,6 +82,21 @@ local function cursor_encode(value) return (encoded:gsub(".", function(char) return string.format("%02x", string.byte(char)) end)) end +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" + +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" +end + local NULL = json.decode("null") local function record_view(row) @@ -211,11 +226,7 @@ local function query_locations(filters, limit, cursor, direction) end binds[#binds + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" - -- CASE guards the cast itself; a WHERE regex cannot protect it from planner reordering. - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - local sort_key = "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" - local sql = "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, to_char(sorted.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp FROM happyview_records CROSS JOIN LATERAL (SELECT " .. sort_key .. " AS sort_at) sorted WHERE " .. table.concat(where, " AND ") .. " ORDER BY sorted.sort_at " .. ordering .. ", uri " .. ordering .. " LIMIT $" .. #binds + local sql = "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, to_char(sorted.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp FROM happyview_records CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted WHERE " .. table.concat(where, " AND ") .. " ORDER BY sorted.sort_at " .. ordering .. ", uri " .. ordering .. " LIMIT $" .. #binds local rows = query(sql, binds) local more = #rows > limit if more then rows[#rows] = nil end diff --git a/happyview-modules/lua/endpoints/listOrganizations.lua b/happyview-modules/lua/endpoints/listOrganizations.lua index c8c76c97..e2e679b6 100644 --- a/happyview-modules/lua/endpoints/listOrganizations.lua +++ b/happyview-modules/lua/endpoints/listOrganizations.lua @@ -200,6 +200,20 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end +-- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. +local function add_in(where, binds, column, items) + if #items == 0 then + where[#where + 1] = "FALSE" + return + end + local marks = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + marks[#marks + 1] = "$" .. #binds + end + where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" +end + local function valid_organization_uri(value) if type(value) ~= "string" or value:find("[?#]") then return false end local authority, collection, rkey = value:match("^at://([^/]+)/([^/]+)/([^/]+)$") @@ -243,17 +257,6 @@ local function array(params, key) return unique end -local function add_actors(where, values, actors) - if not actors then return end - if #actors == 0 then where[#where + 1] = "FALSE"; return end - local placeholders = {} - for _, did in ipairs(actors) do - values[#values + 1] = did - placeholders[#placeholders + 1] = "$" .. #values - end - where[#where + 1] = "organization.did IN (" .. table.concat(placeholders, ", ") .. ")" -end - local function add_organization_types(where, values, organization_types) if not organization_types then return end if #organization_types == 0 then where[#where + 1] = "FALSE"; return end @@ -286,7 +289,7 @@ end local function query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local where, values = { "organization.collection = $1", "organization.rkey = 'self'" }, { ORGANIZATION } - add_actors(where, values, actors) + if actors then add_in(where, values, "organization.did", actors) end add_organization_types(where, values, organization_types) if visibility ~= nil then values[#values + 1] = visibility diff --git a/happyview-modules/lua/endpoints/listProfiles.lua b/happyview-modules/lua/endpoints/listProfiles.lua index f721780f..15ad948e 100644 --- a/happyview-modules/lua/endpoints/listProfiles.lua +++ b/happyview-modules/lua/endpoints/listProfiles.lua @@ -106,6 +106,20 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end +-- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. +local function add_in(where, binds, column, items) + if #items == 0 then + where[#where + 1] = "FALSE" + return + end + local marks = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + marks[#marks + 1] = "$" .. #binds + end + where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" +end + local function valid_profile_uri(value) if type(value) ~= "string" or value:find("[?#]") then return false end local authority, collection, rkey = value:match("^at://([^/]+)/([^/]+)/([^/]+)$") @@ -134,17 +148,6 @@ local function array(params, key) return unique end -local function add_actors(where, values, actors) - if not actors then return end - if #actors == 0 then where[#where + 1] = "FALSE"; return end - local placeholders = {} - for _, did in ipairs(actors) do - values[#values + 1] = did - placeholders[#placeholders + 1] = "$" .. #values - end - where[#where + 1] = "did IN (" .. table.concat(placeholders, ", ") .. ")" -end - local function cursor_decode(token, direction) if not token then return nil end if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end @@ -163,7 +166,7 @@ end local function query_profiles(actors, search, limit, cursor, direction) local where, values = { "collection = $1", "rkey = 'self'" }, { PROFILE } - add_actors(where, values, actors) + if actors then add_in(where, values, "did", actors) end if search then values[#values + 1] = search local term = "$" .. #values diff --git a/happyview-modules/lua/endpoints/searchBadgeDefinitions.lua b/happyview-modules/lua/endpoints/searchBadgeDefinitions.lua index a0e4223c..96d4cca9 100644 --- a/happyview-modules/lua/endpoints/searchBadgeDefinitions.lua +++ b/happyview-modules/lua/endpoints/searchBadgeDefinitions.lua @@ -89,6 +89,21 @@ local function cursor_encode(value) return (encoded:gsub(".", function(char) return string.format("%02x", string.byte(char)) end)) end +local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" + +-- Sort key for a happyview_records row: the record's own createdAt when it is a +-- valid timestamp, otherwise COALESCE(indexed_at, created_at). `alias` is the +-- table alias; nil selects unqualified columns. +local function created_at_sort(alias) + local prefix = alias and (alias .. ".") or "" + local record, indexed_at, created_at = prefix .. "record", prefix .. "indexed_at", prefix .. "created_at" + local created = record .. "::jsonb->>'createdAt'" + return "CASE WHEN jsonb_typeof(" .. record .. "::jsonb->'createdAt') = 'string' AND " .. created .. + " ~ '" .. CREATED_AT_SORT_PATTERN .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. + ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(" .. indexed_at .. + "::timestamptz, " .. created_at .. "::timestamptz) END" +end + local NULL = json.decode("null") local function record_view(row) @@ -194,14 +209,6 @@ local function decode_badge_definition_cursor(token, direction) return value end -local function badge_definition_sort_expression() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" -end - local function query_badge_definitions(authors, badge_types, search, limit, cursor, direction) local where, values = { "collection = $1" }, { COLLECTION } add_badge_definition_filter(where, values, "did", authors) @@ -222,7 +229,7 @@ local function query_badge_definitions(authors, badge_types, search, limit, curs end values[#values + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" - local sort_expression = badge_definition_sort_expression() + local sort_expression = created_at_sort() local sql = "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, " .. "to_char(sorted.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp " .. "FROM happyview_records CROSS JOIN LATERAL (SELECT " .. sort_expression .. " AS sort_at) sorted WHERE " .. diff --git a/happyview-modules/lua/endpoints/searchOrganizations.lua b/happyview-modules/lua/endpoints/searchOrganizations.lua index a8d5f166..e0cef2e4 100644 --- a/happyview-modules/lua/endpoints/searchOrganizations.lua +++ b/happyview-modules/lua/endpoints/searchOrganizations.lua @@ -200,6 +200,20 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end +-- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. +local function add_in(where, binds, column, items) + if #items == 0 then + where[#where + 1] = "FALSE" + return + end + local marks = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + marks[#marks + 1] = "$" .. #binds + end + where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" +end + local function valid_organization_uri(value) if type(value) ~= "string" or value:find("[?#]") then return false end local authority, collection, rkey = value:match("^at://([^/]+)/([^/]+)/([^/]+)$") @@ -243,17 +257,6 @@ local function array(params, key) return unique end -local function add_actors(where, values, actors) - if not actors then return end - if #actors == 0 then where[#where + 1] = "FALSE"; return end - local placeholders = {} - for _, did in ipairs(actors) do - values[#values + 1] = did - placeholders[#placeholders + 1] = "$" .. #values - end - where[#where + 1] = "organization.did IN (" .. table.concat(placeholders, ", ") .. ")" -end - local function add_organization_types(where, values, organization_types) if not organization_types then return end if #organization_types == 0 then where[#where + 1] = "FALSE"; return end @@ -286,7 +289,7 @@ end local function query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local where, values = { "organization.collection = $1", "organization.rkey = 'self'" }, { ORGANIZATION } - add_actors(where, values, actors) + if actors then add_in(where, values, "organization.did", actors) end add_organization_types(where, values, organization_types) if visibility ~= nil then values[#values + 1] = visibility diff --git a/happyview-modules/lua/endpoints/searchProfiles.lua b/happyview-modules/lua/endpoints/searchProfiles.lua index bef76ab5..bdf6c7d6 100644 --- a/happyview-modules/lua/endpoints/searchProfiles.lua +++ b/happyview-modules/lua/endpoints/searchProfiles.lua @@ -106,6 +106,20 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end +-- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. +local function add_in(where, binds, column, items) + if #items == 0 then + where[#where + 1] = "FALSE" + return + end + local marks = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + marks[#marks + 1] = "$" .. #binds + end + where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" +end + local function valid_profile_uri(value) if type(value) ~= "string" or value:find("[?#]") then return false end local authority, collection, rkey = value:match("^at://([^/]+)/([^/]+)/([^/]+)$") @@ -134,17 +148,6 @@ local function array(params, key) return unique end -local function add_actors(where, values, actors) - if not actors then return end - if #actors == 0 then where[#where + 1] = "FALSE"; return end - local placeholders = {} - for _, did in ipairs(actors) do - values[#values + 1] = did - placeholders[#placeholders + 1] = "$" .. #values - end - where[#where + 1] = "did IN (" .. table.concat(placeholders, ", ") .. ")" -end - local function cursor_decode(token, direction) if not token then return nil end if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end @@ -163,7 +166,7 @@ end local function query_profiles(actors, search, limit, cursor, direction) local where, values = { "collection = $1", "rkey = 'self'" }, { PROFILE } - add_actors(where, values, actors) + if actors then add_in(where, values, "did", actors) end if search then values[#values + 1] = search local term = "$" .. #values diff --git a/happyview-modules/lua/shared/actorFollow.lua b/happyview-modules/lua/shared/actorFollow.lua index 388bbb72..ad552b53 100644 --- a/happyview-modules/lua/shared/actorFollow.lua +++ b/happyview-modules/lua/shared/actorFollow.lua @@ -1,12 +1,5 @@ local FOLLOW = "app.certified.graph.follow" --- Guard the cast inside CASE; a WHERE filter cannot protect it from planner reordering. -local function follow_sort_key() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" -end - local function query(sql, values) if db.backend() ~= "postgres" then error("ActorFollowQueryFailed: actor-follow queries require PostgreSQL", 0) end local ok, result = pcall(db.raw, sql, values) diff --git a/happyview-modules/lua/shared/actorFollowList.lua b/happyview-modules/lua/shared/actorFollowList.lua index 76f1b3f5..329fe35e 100644 --- a/happyview-modules/lua/shared/actorFollowList.lua +++ b/happyview-modules/lua/shared/actorFollowList.lua @@ -41,7 +41,7 @@ local function build_actor_follow_query(mode, actor, limit, cursor, direction) values[#values + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" local displayed_did = mode == "followers" and "did" or "subject_did" - local sql = "WITH ranked_follows AS (SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, record::jsonb->>'subject' AS subject_did, sorted.sort_at, ROW_NUMBER() OVER (PARTITION BY did, record::jsonb->>'subject' ORDER BY sorted.sort_at ASC, uri ASC) AS relationship_rank FROM happyview_records CROSS JOIN LATERAL (SELECT " .. follow_sort_key() .. " AS sort_at) sorted WHERE " .. table.concat(filters, " AND ") .. "), representatives AS (SELECT uri, did, cid, indexed_at, record, sort_at, " .. displayed_did .. " AS actor_did FROM ranked_follows WHERE relationship_rank = 1), " .. + local sql = "WITH ranked_follows AS (SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, record::jsonb->>'subject' AS subject_did, sorted.sort_at, ROW_NUMBER() OVER (PARTITION BY did, record::jsonb->>'subject' ORDER BY sorted.sort_at ASC, uri ASC) AS relationship_rank FROM happyview_records CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted WHERE " .. table.concat(filters, " AND ") .. "), representatives AS (SELECT uri, did, cid, indexed_at, record, sort_at, " .. displayed_did .. " AS actor_did FROM ranked_follows WHERE relationship_rank = 1), " .. "total AS (SELECT COUNT(*) AS total_count FROM representatives), " .. "page AS (SELECT uri, did, cid, indexed_at, record, sort_at, actor_did FROM representatives" .. cursor_filter .. " ORDER BY sort_at " .. ordering .. ", uri " .. ordering .. " LIMIT $" .. #values .. ") " .. "SELECT page.uri, page.did, page.cid, page.indexed_at, page.record, page.actor_did, total.total_count, to_char(page.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp FROM total LEFT JOIN page ON TRUE ORDER BY page.sort_at " .. ordering .. ", page.uri " .. ordering diff --git a/happyview-modules/lua/shared/actorFollowLookup.lua b/happyview-modules/lua/shared/actorFollowLookup.lua index 832391c8..a32c3077 100644 --- a/happyview-modules/lua/shared/actorFollowLookup.lua +++ b/happyview-modules/lua/shared/actorFollowLookup.lua @@ -1,6 +1,6 @@ local function query_follow(actor, subject) local rows = query( - "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record FROM happyview_records CROSS JOIN LATERAL (SELECT " .. follow_sort_key() .. " AS sort_at) sorted WHERE collection = $1 AND did = $2 AND record::jsonb->>'subject' = $3 AND " .. account_follow_filter_sql() .. " ORDER BY sorted.sort_at ASC, uri ASC LIMIT 1", + "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record FROM happyview_records CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted WHERE collection = $1 AND did = $2 AND record::jsonb->>'subject' = $3 AND " .. account_follow_filter_sql() .. " ORDER BY sorted.sort_at ASC, uri ASC LIMIT 1", { FOLLOW, actor, subject }) if #rows == 0 then return NULL end return record_view(rows[1]) diff --git a/happyview-modules/lua/shared/organizationList.lua b/happyview-modules/lua/shared/organizationList.lua index 67721f1f..3c9d3929 100644 --- a/happyview-modules/lua/shared/organizationList.lua +++ b/happyview-modules/lua/shared/organizationList.lua @@ -41,17 +41,6 @@ local function array(params, key) return unique end -local function add_actors(where, values, actors) - if not actors then return end - if #actors == 0 then where[#where + 1] = "FALSE"; return end - local placeholders = {} - for _, did in ipairs(actors) do - values[#values + 1] = did - placeholders[#placeholders + 1] = "$" .. #values - end - where[#where + 1] = "organization.did IN (" .. table.concat(placeholders, ", ") .. ")" -end - local function add_organization_types(where, values, organization_types) if not organization_types then return end if #organization_types == 0 then where[#where + 1] = "FALSE"; return end @@ -84,7 +73,7 @@ end local function query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local where, values = { "organization.collection = $1", "organization.rkey = 'self'" }, { ORGANIZATION } - add_actors(where, values, actors) + if actors then add_in(where, values, "organization.did", actors) end add_organization_types(where, values, organization_types) if visibility ~= nil then values[#values + 1] = visibility diff --git a/happyview-modules/lua/shared/profileList.lua b/happyview-modules/lua/shared/profileList.lua index eb28a59b..b2af0734 100644 --- a/happyview-modules/lua/shared/profileList.lua +++ b/happyview-modules/lua/shared/profileList.lua @@ -26,17 +26,6 @@ local function array(params, key) return unique end -local function add_actors(where, values, actors) - if not actors then return end - if #actors == 0 then where[#where + 1] = "FALSE"; return end - local placeholders = {} - for _, did in ipairs(actors) do - values[#values + 1] = did - placeholders[#placeholders + 1] = "$" .. #values - end - where[#where + 1] = "did IN (" .. table.concat(placeholders, ", ") .. ")" -end - local function cursor_decode(token, direction) if not token then return nil end if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end @@ -55,7 +44,7 @@ end local function query_profiles(actors, search, limit, cursor, direction) local where, values = { "collection = $1", "rkey = 'self'" }, { PROFILE } - add_actors(where, values, actors) + if actors then add_in(where, values, "did", actors) end if search then values[#values + 1] = search local term = "$" .. #values diff --git a/happyview-modules/lua/src/getFollows.lua b/happyview-modules/lua/src/getFollows.lua index 8c2e4745..12692739 100644 --- a/happyview-modules/lua/src/getFollows.lua +++ b/happyview-modules/lua/src/getFollows.lua @@ -16,7 +16,7 @@ local function get_follows() .. "SELECT DISTINCT ON (requested.target) requested.target AS target, uri, did, cid, " .. "indexed_at::text AS indexed_at, record::text AS record FROM requested " .. "JOIN happyview_records ON collection = $1 AND did = $2 AND record::jsonb->>'subject' = requested.target AND " .. account_follow_filter_sql() .. " " - .. "CROSS JOIN LATERAL (SELECT " .. follow_sort_key() .. " AS sort_at) sorted " + .. "CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted " .. "ORDER BY requested.target, sorted.sort_at ASC, uri ASC", values) if type(rows) ~= "table" then error("ActorFollowQueryFailed: actor-follow lookup failed", 0) end diff --git a/happyview-modules/lua/src/listBadgeAwards.lua b/happyview-modules/lua/src/listBadgeAwards.lua index 7ad2b1e0..cb2c291b 100644 --- a/happyview-modules/lua/src/listBadgeAwards.lua +++ b/happyview-modules/lua/src/listBadgeAwards.lua @@ -134,15 +134,6 @@ local function decode_badge_award_cursor(token, direction) return value end -local function award_sort_expression() - local created = "award.record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(award.record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE " .. - "COALESCE(award.indexed_at::timestamptz, award.created_at::timestamptz) END" -end - local function recipient_did_expression() local subject = "award.record::jsonb->'subject'" return "CASE WHEN jsonb_typeof(" .. subject .. ") = 'string' THEN award.record::jsonb->>'subject' " .. @@ -239,7 +230,7 @@ local function list_badge_awards(authors, badge_uris, badge_types, subjects, res "recipient_response.uri AS recipient_response_uri, recipient_response.cid AS recipient_response_cid, " .. "recipient_response.indexed_at::text AS recipient_response_indexed_at, " .. "recipient_response.did AS recipient_response_did, recipient_response.record::text AS recipient_response_record " .. - "FROM happyview_records AS award CROSS JOIN LATERAL (SELECT " .. award_sort_expression() .. " AS sort_at) sorted " .. + "FROM happyview_records AS award CROSS JOIN LATERAL (SELECT " .. created_at_sort("award") .. " AS sort_at) sorted " .. "LEFT JOIN happyview_records AS badge ON badge.collection = '" .. DEFINITION .. "' " .. "AND badge.uri = award.record::jsonb->'badge'->>'uri' " .. "AND badge.cid = award.record::jsonb->'badge'->>'cid' " .. diff --git a/happyview-modules/lua/src/listBadgeDefinitions.lua b/happyview-modules/lua/src/listBadgeDefinitions.lua index 8888edbf..04adc448 100644 --- a/happyview-modules/lua/src/listBadgeDefinitions.lua +++ b/happyview-modules/lua/src/listBadgeDefinitions.lua @@ -58,14 +58,6 @@ local function decode_badge_definition_cursor(token, direction) return value end -local function badge_definition_sort_expression() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" -end - local function list_badge_definitions(authors, badge_types, limit, cursor, direction) if db.backend() ~= "postgres" then error("BadgeDefinitionQueryFailed: badge definition API requires PostgreSQL", 0) @@ -83,7 +75,7 @@ local function list_badge_definitions(authors, badge_types, limit, cursor, direc end values[#values + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" - local sort_expression = badge_definition_sort_expression() + local sort_expression = created_at_sort() local sql = "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, " .. "to_char(sorted.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp " .. "FROM happyview_records CROSS JOIN LATERAL (SELECT " .. sort_expression .. " AS sort_at) sorted WHERE " .. diff --git a/happyview-modules/lua/src/listBadgeResponses.lua b/happyview-modules/lua/src/listBadgeResponses.lua index b7aea299..cb0c4a61 100644 --- a/happyview-modules/lua/src/listBadgeResponses.lua +++ b/happyview-modules/lua/src/listBadgeResponses.lua @@ -36,15 +36,6 @@ local function decode_badge_response_cursor(token, direction) return value end -local function response_sort_expression() - local created = "response.record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(response.record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE " .. - "COALESCE(response.indexed_at::timestamptz, response.created_at::timestamptz) END" -end - local function list_badge_responses(badge_award, limit, cursor, direction) local where, values = { "response.collection = $1" }, { RESPONSE } if badge_award then @@ -65,7 +56,7 @@ local function list_badge_responses(badge_award, limit, cursor, direction) local sql = "SELECT response.uri, response.did, response.cid, response.indexed_at::text AS indexed_at, " .. "response.record::text AS record, to_char(sorted.sort_at AT TIME ZONE 'UTC', " .. "'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp " .. - "FROM happyview_records AS response CROSS JOIN LATERAL (SELECT " .. response_sort_expression() .. " AS sort_at) sorted " .. + "FROM happyview_records AS response CROSS JOIN LATERAL (SELECT " .. created_at_sort("response") .. " AS sort_at) sorted " .. "WHERE " .. table.concat(where, " AND ") .. " ORDER BY sorted.sort_at " .. ordering .. ", response.uri " .. ordering .. " LIMIT $" .. #values local rows = query(sql, values) diff --git a/happyview-modules/lua/src/listEvmLinks.lua b/happyview-modules/lua/src/listEvmLinks.lua index b6d70faf..ea031da9 100644 --- a/happyview-modules/lua/src/listEvmLinks.lua +++ b/happyview-modules/lua/src/listEvmLinks.lua @@ -77,16 +77,6 @@ local function decode_evm_link_cursor(token, direction) return value end -local function evm_link_sort_key() - -- CASE guards the cast from malformed publisher-controlled timestamps. - local created = "link.record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(link.record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE " .. - "COALESCE(link.indexed_at::timestamptz, link.created_at::timestamptz) END" -end - local function list_evm_links(actors, addresses, limit, cursor, direction) local where, values = { "link.collection = $1" }, { EVMLINK } add_filter(where, values, "link.did", actors) @@ -107,7 +97,7 @@ local function list_evm_links(actors, addresses, limit, cursor, direction) local sql = "SELECT link.uri, link.did, link.cid, link.indexed_at::text AS indexed_at, " .. "link.record::text AS record, to_char(sorted.sort_at AT TIME ZONE 'UTC', " .. "'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp " .. - "FROM happyview_records AS link CROSS JOIN LATERAL (SELECT " .. evm_link_sort_key() .. " AS sort_at) sorted WHERE " .. + "FROM happyview_records AS link CROSS JOIN LATERAL (SELECT " .. created_at_sort("link") .. " AS sort_at) sorted WHERE " .. table.concat(where, " AND ") .. " ORDER BY sorted.sort_at " .. ordering .. ", link.uri " .. ordering .. " LIMIT $" .. #values local rows = evm_link_query(sql, values) diff --git a/happyview-modules/lua/src/listFeatures.lua b/happyview-modules/lua/src/listFeatures.lua index acec60ca..9de46453 100644 --- a/happyview-modules/lua/src/listFeatures.lua +++ b/happyview-modules/lua/src/listFeatures.lua @@ -38,20 +38,6 @@ local function feature_array(params, key, validate, description, max_bytes) return unique end -local function feature_add_in(where, values, column, binds) - if values == nil then return end - if #values == 0 then - where[#where + 1] = "FALSE" - return - end - local placeholders = {} - for _, value in ipairs(values) do - binds[#binds + 1] = value - placeholders[#placeholders + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(placeholders, ", ") .. ")" -end - local function feature_add_types(where, values, binds) if values == nil then return end if #values == 0 then @@ -117,7 +103,7 @@ end local function feature_list_rows(filters, limit, cursor, direction) local where, binds = { "feature.collection = $1" }, { FEATURE_COLLECTION } - feature_add_in(where, filters.authors, "feature.did", binds) + if filters.authors then add_in(where, binds, "feature.did", filters.authors) end feature_add_types(where, filters.types, binds) if filters.hasOrganizationRecord ~= nil then local predicate = filters.hasOrganizationRecord and "EXISTS" or "NOT EXISTS" diff --git a/happyview-modules/lua/src/listLocations.lua b/happyview-modules/lua/src/listLocations.lua index f3eaeb07..4cb48ff8 100644 --- a/happyview-modules/lua/src/listLocations.lua +++ b/happyview-modules/lua/src/listLocations.lua @@ -62,11 +62,7 @@ local function query_locations(filters, limit, cursor, direction) end binds[#binds + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" - -- CASE guards the cast itself; a WHERE regex cannot protect it from planner reordering. - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - local sort_key = "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" - local sql = "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, to_char(sorted.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp FROM happyview_records CROSS JOIN LATERAL (SELECT " .. sort_key .. " AS sort_at) sorted WHERE " .. table.concat(where, " AND ") .. " ORDER BY sorted.sort_at " .. ordering .. ", uri " .. ordering .. " LIMIT $" .. #binds + local sql = "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, to_char(sorted.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp FROM happyview_records CROSS JOIN LATERAL (SELECT " .. created_at_sort() .. " AS sort_at) sorted WHERE " .. table.concat(where, " AND ") .. " ORDER BY sorted.sort_at " .. ordering .. ", uri " .. ordering .. " LIMIT $" .. #binds local rows = query(sql, binds) local more = #rows > limit if more then rows[#rows] = nil end diff --git a/happyview-modules/lua/src/searchBadgeDefinitions.lua b/happyview-modules/lua/src/searchBadgeDefinitions.lua index 32706d6c..76d71297 100644 --- a/happyview-modules/lua/src/searchBadgeDefinitions.lua +++ b/happyview-modules/lua/src/searchBadgeDefinitions.lua @@ -61,14 +61,6 @@ local function decode_badge_definition_cursor(token, direction) return value end -local function badge_definition_sort_expression() - local created = "record::jsonb->>'createdAt'" - local zoned = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" - return "CASE WHEN jsonb_typeof(record::jsonb->'createdAt') = 'string' AND " .. created .. - " ~ '" .. zoned .. "' AND " .. created .. " !~ '-00:00$' AND pg_input_is_valid(" .. created .. - ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" -end - local function query_badge_definitions(authors, badge_types, search, limit, cursor, direction) local where, values = { "collection = $1" }, { COLLECTION } add_badge_definition_filter(where, values, "did", authors) @@ -89,7 +81,7 @@ local function query_badge_definitions(authors, badge_types, search, limit, curs end values[#values + 1] = limit + 1 local ordering = direction == "asc" and "ASC" or "DESC" - local sort_expression = badge_definition_sort_expression() + local sort_expression = created_at_sort() local sql = "SELECT uri, did, cid, indexed_at::text AS indexed_at, record::text AS record, " .. "to_char(sorted.sort_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') AS sort_timestamp " .. "FROM happyview_records CROSS JOIN LATERAL (SELECT " .. sort_expression .. " AS sort_at) sorted WHERE " .. diff --git a/happyview-modules/modules/actor-follow/manifest.json b/happyview-modules/modules/actor-follow/manifest.json index 45741dcf..a6be14ea 100644 --- a/happyview-modules/modules/actor-follow/manifest.json +++ b/happyview-modules/modules/actor-follow/manifest.json @@ -50,6 +50,7 @@ "../../lua/shared/query.lua", "../../lua/shared/recordView.lua", "../../lua/shared/accountFollowFilter.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/actorFollow.lua", "../../lua/shared/actorFollowLookup.lua" ], @@ -69,6 +70,7 @@ "../../lua/shared/query.lua", "../../lua/shared/recordView.lua", "../../lua/shared/accountFollowFilter.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/actorFollow.lua", "../../lua/shared/batchRequestTarget.lua", "../../lua/shared/followBatch.lua" @@ -94,6 +96,7 @@ "../../lua/shared/recordView.lua", "../../lua/shared/actorView.lua", "../../lua/shared/accountFollowFilter.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/actorFollow.lua", "../../lua/shared/actorFollowList.lua" ], @@ -118,6 +121,7 @@ "../../lua/shared/recordView.lua", "../../lua/shared/actorView.lua", "../../lua/shared/accountFollowFilter.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/actorFollow.lua", "../../lua/shared/actorFollowList.lua" ], diff --git a/happyview-modules/modules/badge-definitions/manifest.json b/happyview-modules/modules/badge-definitions/manifest.json index 72d69b72..4c5d7369 100644 --- a/happyview-modules/modules/badge-definitions/manifest.json +++ b/happyview-modules/modules/badge-definitions/manifest.json @@ -57,6 +57,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listQuery.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/recordView.lua", "../../lua/shared/actorView.lua" ], diff --git a/happyview-modules/modules/badge-queries/manifest.json b/happyview-modules/modules/badge-queries/manifest.json index 0d4b8f17..bec7aa3e 100644 --- a/happyview-modules/modules/badge-queries/manifest.json +++ b/happyview-modules/modules/badge-queries/manifest.json @@ -68,6 +68,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listQuery.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/recordView.lua", "../../lua/shared/actorView.lua" ], @@ -107,6 +108,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listQuery.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/recordView.lua", "../../lua/shared/actorView.lua", "../../lua/shared/nsidValidation.lua" @@ -147,6 +149,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listQuery.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/recordView.lua", "../../lua/shared/actorView.lua" ], diff --git a/happyview-modules/modules/evm-links/manifest.json b/happyview-modules/modules/evm-links/manifest.json index 56afbfa5..4d5bbd81 100644 --- a/happyview-modules/modules/evm-links/manifest.json +++ b/happyview-modules/modules/evm-links/manifest.json @@ -52,6 +52,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listQuery.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/recordView.lua", "../../lua/shared/evmLinkIdentifier.lua", "../../lua/shared/actorView.lua" diff --git a/happyview-modules/modules/features/manifest.json b/happyview-modules/modules/features/manifest.json index 414d9e3d..00ca2c24 100644 --- a/happyview-modules/modules/features/manifest.json +++ b/happyview-modules/modules/features/manifest.json @@ -48,6 +48,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listQuery.lua", + "../../lua/shared/listWhere.lua", "../../lua/shared/featureValidation.lua", "../../lua/shared/featureProjection.lua" ], diff --git a/happyview-modules/modules/location/manifest.json b/happyview-modules/modules/location/manifest.json index 7b32066c..cdf1ab5d 100644 --- a/happyview-modules/modules/location/manifest.json +++ b/happyview-modules/modules/location/manifest.json @@ -51,6 +51,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listQuery.lua", + "../../lua/shared/createdAtSort.lua", "../../lua/shared/recordView.lua", "../../lua/shared/actorView.lua", "../../lua/shared/location.lua" diff --git a/happyview-modules/modules/organization/manifest.json b/happyview-modules/modules/organization/manifest.json index dc36d222..08f13643 100644 --- a/happyview-modules/modules/organization/manifest.json +++ b/happyview-modules/modules/organization/manifest.json @@ -96,6 +96,7 @@ "../../lua/shared/recordView.lua", "../../lua/shared/organization.lua", "../../lua/shared/createdAtSort.lua", + "../../lua/shared/listWhere.lua", "../../lua/shared/organizationList.lua" ], "config": { @@ -119,6 +120,7 @@ "../../lua/shared/recordView.lua", "../../lua/shared/organization.lua", "../../lua/shared/createdAtSort.lua", + "../../lua/shared/listWhere.lua", "../../lua/shared/organizationList.lua" ], "config": { diff --git a/happyview-modules/modules/profile/manifest.json b/happyview-modules/modules/profile/manifest.json index 72ce97ff..278ba9d3 100644 --- a/happyview-modules/modules/profile/manifest.json +++ b/happyview-modules/modules/profile/manifest.json @@ -89,6 +89,7 @@ "../../lua/shared/recordView.lua", "../../lua/shared/profile.lua", "../../lua/shared/createdAtSort.lua", + "../../lua/shared/listWhere.lua", "../../lua/shared/profileList.lua" ], "config": { @@ -111,6 +112,7 @@ "../../lua/shared/recordView.lua", "../../lua/shared/profile.lua", "../../lua/shared/createdAtSort.lua", + "../../lua/shared/listWhere.lua", "../../lua/shared/profileList.lua" ], "config": { diff --git a/happyview-modules/tests/unit/feature.test.js b/happyview-modules/tests/unit/feature.test.js index ee1beb02..ba08b923 100644 --- a/happyview-modules/tests/unit/feature.test.js +++ b/happyview-modules/tests/unit/feature.test.js @@ -139,6 +139,7 @@ async function runListFeatures( "lua/shared/datetimeValidation.lua", "lua/shared/listValidation.lua", "lua/shared/listQuery.lua", + "lua/shared/listWhere.lua", "lua/shared/featureValidation.lua", "lua/shared/recordView.lua", "lua/shared/featureProjection.lua",