The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix: pg_graphql performance (#3204)
Jérémy M2dae94dec626
diff --git a/packages/twenty-postgres/macos/arm/15/pg_graphql/1.4.2/pg_graphql--1.4.2.sql b/packages/twenty-postgres/macos/arm/15/pg_graphql/1.4.2/pg_graphql--1.4.2.sqlindex bc0698bd683..7bafc8f7df5 100644--- a/packages/twenty-postgres/macos/arm/15/pg_graphql/1.4.2/pg_graphql--1.4.2.sql+++ b/packages/twenty-postgres/macos/arm/15/pg_graphql/1.4.2/pg_graphql--1.4.2.sql@@ -16,6 +16,60 @@ CREATE FUNCTION graphql."_internal_resolve"(LANGUAGE c /* Rust */AS 'MODULE_PATHNAME', 'resolve_wrapper';+-- src/lib.rs:19+-- Is updated every time the schema changes+create sequence if not exists graphql.seq_schema_version as int cycle;++create or replace function graphql.increment_schema_version()+ returns event_trigger+ security definer+ language plpgsql+as $$+begin+ perform nextval('graphql.seq_schema_version');+end;+$$;++create or replace function graphql.get_schema_version()+ returns int+ security definer+ language sql+as $$+ select last_value from graphql.seq_schema_version;+$$;++-- On DDL event, increment the schema version number+create event trigger graphql_watch_ddl+ on ddl_command_end+ execute procedure graphql.increment_schema_version();++create event trigger graphql_watch_drop+ on sql_drop+ execute procedure graphql.increment_schema_version();+++-- src/lib.rs:20+create function graphql.comment_directive(comment_ text)+ returns jsonb+ language sql+ immutable+as $$+ /*+ comment on column public.account.name is '@graphql.name: myField'+ */+ select+ coalesce(+ (+ regexp_match(+ comment_,+ '@graphql\((.+?)\)'+ )+ )[1]::jsonb,+ jsonb_build_object()+ )+$$;++-- src/lib.rs:22-- requires:-- resolve@@ -50,28 +104,6 @@ end;$$;--- src/lib.rs:20-create function graphql.comment_directive(comment_ text)- returns jsonb- language sql- immutable-as $$- /*- comment on column public.account.name is '@graphql.name: myField'- */- select- coalesce(- (- regexp_match(- comment_,- '@graphql\((.+?)\)'- )- )[1]::jsonb,- jsonb_build_object()- )-$$;---- src/lib.rs:21create or replace function graphql.exception(message text)returns text@@ -82,35 +114,3 @@ beginend;$$;---- src/lib.rs:19--- Is updated every time the schema changes-create sequence if not exists graphql.seq_schema_version as int cycle;--create or replace function graphql.increment_schema_version()- returns event_trigger- security definer- language plpgsql-as $$-begin- perform nextval('graphql.seq_schema_version');-end;-$$;--create or replace function graphql.get_schema_version()- returns int- security definer- language sql-as $$- select last_value from graphql.seq_schema_version;-$$;---- On DDL event, increment the schema version number-create event trigger graphql_watch_ddl- on ddl_command_end- execute procedure graphql.increment_schema_version();--create event trigger graphql_watch_drop- on sql_drop- execute procedure graphql.increment_schema_version();-diff --git a/packages/twenty-postgres/macos/arm/15/pg_graphql/1.4.2/pg_graphql.so b/packages/twenty-postgres/macos/arm/15/pg_graphql/1.4.2/pg_graphql.soindex 98f5188abe5..a3abd03724f 100755Binary files a/packages/twenty-postgres/macos/arm/15/pg_graphql/1.4.2/pg_graphql.so and b/packages/twenty-postgres/macos/arm/15/pg_graphql/1.4.2/pg_graphql.so differdiff --git a/packages/twenty-postgres/macos/arm/build-postgres-macos-arm.sh b/packages/twenty-postgres/macos/arm/build-postgres-macos-arm.shindex 97578c0b1ac..5bfbb399489 100755--- a/packages/twenty-postgres/macos/arm/build-postgres-macos-arm.sh+++ b/packages/twenty-postgres/macos/arm/build-postgres-macos-arm.sh@@ -48,10 +48,11 @@ EOFecho_header $BLUE " DATABASE SETUP"PG_MAIN_VERSION=15-PG_GRAPHQL_VERSION=1.3.0-CARGO_PGRX_VERSION=0.9.8+PG_GRAPHQL_VERSION=1.4.2+CARGO_PGRX_VERSION=0.10.2current_directory=$(pwd)+script_directory="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"# Install PostgresSQLecho_header $GREEN "Step [1/4]: Installing PostgreSQL..."@@ -85,9 +86,17 @@ unzip pg_graphql-$PG_GRAPHQL_VERSION.zip[[ ":$PATH:" != *":/opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin:"* ]] && PATH="/opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin:${PATH}"cd "pg_graphql-$PG_GRAPHQL_VERSION"++# Apply patches to pg_graphql files+echo "Applying patches to pg_graphql files..."+for patch_file in "$script_directory/../../patches/pg_graphql/"*.patch; do+ echo "Applying patch: $patch_file"+ patch -p1 < "$patch_file"+done+cargo pgrx install --release --pg-config /opt/homebrew/opt/postgresql@$PG_MAIN_VERSION/bin/pg_config-# # Clean up the temporary directory+# Clean up the temporary directoryecho "Cleaning up..."cd "$current_directory"rm -rf "$temp_dir"diff --git a/packages/twenty-postgres/macos/intel/build-postgres-macos-intel.sh b/packages/twenty-postgres/macos/intel/build-postgres-macos-intel.shindex 4848485e815..743f812ca98 100755--- a/packages/twenty-postgres/macos/intel/build-postgres-macos-intel.sh+++ b/packages/twenty-postgres/macos/intel/build-postgres-macos-intel.sh@@ -48,10 +48,11 @@ EOFecho_header $BLUE " DATABASE SETUP"PG_MAIN_VERSION=15-PG_GRAPHQL_VERSION=1.3.0-CARGO_PGRX_VERSION=0.9.8+PG_GRAPHQL_VERSION=1.4.2+CARGO_PGRX_VERSION=0.10.2current_directory=$(pwd)+script_directory="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"# Install PostgresSQLecho_header $GREEN "Step [1/4]: Installing PostgreSQL..."@@ -85,9 +86,17 @@ unzip pg_graphql-$PG_GRAPHQL_VERSION.zip[[ ":$PATH:" != *":/usr/local/opt/postgresql@$PG_MAIN_VERSION/bin:"* ]] && PATH="/usr/local/opt/postgresql@$PG_MAIN_VERSION/bin:${PATH}"cd "pg_graphql-$PG_GRAPHQL_VERSION"++# Apply patches to pg_graphql files+echo "Applying patches to pg_graphql files..."+for patch_file in "$script_directory/../../patches/pg_graphql/"*.patch; do+ echo "Applying patch: $patch_file"+ patch -p1 < "$patch_file"+done+cargo pgrx install --release --pg-config /usr/local/opt/postgresql@$PG_MAIN_VERSION/bin/pg_config-# # Clean up the temporary directory+# Clean up the temporary directoryecho "Cleaning up..."cd "$current_directory"rm -rf "$temp_dir"diff --git a/packages/twenty-postgres/patches/pg_graphql/0001-performance.patch b/packages/twenty-postgres/patches/pg_graphql/0001-performance.patchnew file mode 100644index 00000000000..e0d35c950e3--- /dev/null+++ b/packages/twenty-postgres/patches/pg_graphql/0001-performance.patch@@ -0,0 +1,28 @@+diff --git a/sql/load_sql_context.sql b/sql/load_sql_context.sql+index 565e4e3..40cd99e 100644+--- a/sql/load_sql_context.sql++++ b/sql/load_sql_context.sql+@@ -95,6 +95,8 @@ select+ pg_type pt+ left join pg_class tabs+ on pt.typrelid = tabs.oid++ join search_path_oids spo++ on pt.typnamespace = spo.schema_oid or pt.typnamespace = 'pg_catalog'::regnamespace::oid+ ),+ jsonb_build_object()+ ),+@@ -111,6 +113,8 @@ select+ pg_type pt+ join pg_class tabs+ on pt.typrelid = tabs.oid++ join search_path_oids spo++ on pt.typnamespace = spo.schema_oid or pt.typnamespace = 'pg_catalog'::regnamespace::oid+ where+ pt.typcategory = 'C'+ and tabs.relkind = 'c'+@@ -420,4 +424,4 @@ select+ jsonb_build_array()+ )++- )++ );