Skip to content

Commit 54109b2

Browse files
committed
coderabbit optimization
1 parent 61c2ff9 commit 54109b2

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/database/supabase/migrations/20250616212706_generate-arity.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
ALTER TABLE "public"."Concept" DROP COLUMN "arity";
2-
3-
ALTER TABLE "public"."Concept" ADD COLUMN "arity" smallint GENERATED ALWAYS AS (compute_arity_local(schema_id, literal_content)) STORED;
4-
51
CREATE OR REPLACE FUNCTION public.compute_arity_id(p_schema_id bigint)
62
RETURNS smallint
73
LANGUAGE sql
84
IMMUTABLE
95
AS $function$
10-
WITH q AS (SELECT jsonb_path_query(literal_content, '$.roles[*]') FROM public."Concept" WHERE id=p_schema_id) SELECT count(*) FROM q;
6+
SELECT COALESCE(jsonb_array_length(literal_content->'roles'), 0) FROM public."Concept" WHERE id=p_schema_id;
117
$function$;
128

139
CREATE OR REPLACE FUNCTION public.compute_arity_lit(lit_content jsonb)
1410
RETURNS smallint
1511
LANGUAGE sql
1612
IMMUTABLE
1713
AS $function$
18-
WITH q AS (SELECT jsonb_path_query(lit_content, '$.roles[*]')) SELECT count(*) FROM q;
14+
SELECT COALESCE(jsonb_array_length(lit_content->'roles'), 0);
1915
$function$;
2016

2117
CREATE OR REPLACE FUNCTION public.compute_arity_local(schema_id bigint, lit_content jsonb)
@@ -26,6 +22,10 @@ AS $function$
2622
SELECT CASE WHEN schema_id IS NULL THEN compute_arity_lit(lit_content) ELSE compute_arity_id(schema_id) END;
2723
$function$;
2824

25+
ALTER TABLE "public"."Concept" DROP COLUMN "arity";
26+
27+
ALTER TABLE "public"."Concept" ADD COLUMN "arity" smallint GENERATED ALWAYS AS (compute_arity_local(schema_id, literal_content)) STORED;
28+
2929
CREATE OR REPLACE FUNCTION public.extract_references(refs jsonb)
3030
RETURNS bigint []
3131
LANGUAGE sql

packages/database/supabase/schemas/concept.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ CREATE OR REPLACE FUNCTION extract_references(refs JSONB) RETURNS BIGINT [] LANG
1717
$$;
1818

1919
CREATE OR REPLACE FUNCTION compute_arity_lit(lit_content JSONB) RETURNS smallint language sql IMMUTABLE AS $$
20-
WITH q AS (SELECT jsonb_path_query(lit_content, '$.roles[*]')) SELECT count(*) FROM q;
20+
SELECT COALESCE(jsonb_array_length(lit_content->'roles'), 0);
2121
$$;
2222

2323
SET check_function_bodies = false;
2424
CREATE OR REPLACE FUNCTION compute_arity_id(p_schema_id BIGINT) RETURNS smallint language sql IMMUTABLE AS $$
25-
WITH q AS (SELECT jsonb_path_query(literal_content, '$.roles[*]') FROM public."Concept" WHERE id=p_schema_id) SELECT count(*) FROM q;
25+
SELECT COALESCE(jsonb_array_length(literal_content->'roles'), 0) FROM public."Concept" WHERE id=p_schema_id;
2626
$$;
2727
SET check_function_bodies = true;
2828

0 commit comments

Comments
 (0)