diff --git a/.cargo/config.toml b/.cargo/config.toml index a66b2d8b98..a2e6bac554 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,10 +1,4 @@ [target.x86_64-unknown-linux-gnu] rustflags = [ "-C", "link-arg=-fuse-ld=lld", - "--cfg", "tokio_unstable", -] - -[build] -rustflags = [ - "--cfg", "tokio_unstable", ] diff --git a/Cargo.lock b/Cargo.lock index 373f822c36..f8f99a1ee7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -46,9 +46,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a" +checksum = "b9a8f622bcf6ff3df478e9deba3e03e4e04b300f8e6a139e192c05fa3490afc7" [[package]] name = "async-channel" @@ -261,9 +261,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -349,9 +349,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.19" +version = "3.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68d43934757334b5c0519ff882e1ab9647ac0258b47c24c4f490d78e42697fd5" +checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd" dependencies = [ "atty", "bitflags", @@ -502,9 +502,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc948ebb96241bb40ab73effeb80d9f93afaad49359d159a5e61be51619fe813" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] @@ -918,7 +918,7 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "block-buffer 0.10.2", + "block-buffer 0.10.3", "crypto-common", "subtle", ] @@ -1677,9 +1677,9 @@ checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" [[package]] name = "md-5" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "274fd6bd98a3c75c9515d9393b063099f60f9b47f09ee20a34fd76287fd017f4" +checksum = "66b48670c893079d3c2ed79114e3644b7004df1c361a4e0ad52e2e6940d07c3d" dependencies = [ "digest 0.10.3", ] @@ -1713,9 +1713,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", ] @@ -1921,9 +1921,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" [[package]] name = "opaque-debug" @@ -2239,7 +2239,7 @@ dependencies = [ "md-5", "memchr", "rand", - "sha2 0.10.3", + "sha2 0.10.5", "stringprep", ] @@ -2766,9 +2766,9 @@ dependencies = [ [[package]] name = "serde-aux" -version = "3.1.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a77223b653fa95f3f9864f3eb25b93e4ed170687eb42d85b6b98af21d5e1de" +checksum = "c79c1a5a310c28bf9f7a4b9bd848553051120d80a5952f993c7eb62f6ed6e4c5" dependencies = [ "chrono", "serde", @@ -2870,9 +2870,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.10" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a09f551ccc8210268ef848f0bab37b306e87b85b2e017b899e7fb815f5aed62" +checksum = "89f31df3f50926cdf2855da5fd8812295c34752cb20438dae42a67f79e021ac3" dependencies = [ "indexmap", "itoa", @@ -2907,9 +2907,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899bf02746a2c92bf1053d9327dadb252b01af1f81f90cdb902411f518bc7215" +checksum = "cf9db03534dff993187064c4e0c05a5708d2a9728ace9a8959b77bedf415dac5" dependencies = [ "cfg-if", "cpufeatures", @@ -3024,9 +3024,9 @@ checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "socket2" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10c98bba371b9b22a71a9414e420f92ddeb2369239af08200816169d5e2dd7aa" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -3197,18 +3197,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57" +checksum = "8c1b05ca9d106ba7d2e31a9dab4a64e7be2cce415321966ea3132c49a656e252" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09" +checksum = "e8f2591983642de85c921015f3f070c665a197ed69e417af436115e3a1407487" dependencies = [ "proc-macro2", "quote", @@ -3264,9 +3264,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42" dependencies = [ "autocfg 1.1.0", "bytes", diff --git a/lib/dal/Cargo.toml b/lib/dal/Cargo.toml index 2394098390..b0ea7b9159 100644 --- a/lib/dal/Cargo.toml +++ b/lib/dal/Cargo.toml @@ -19,7 +19,7 @@ rand = "0.8.3" refinery = "0.8.4" serde = { version = "1.0.123", features = ["rc", "derive"] } serde_json = { version = "1.0.64", features = ["preserve_order"] } -serde-aux = "3.0.1" +serde-aux = "4.0.0" si-data = { path = "../../lib/si-data", features = ["nats", "pg"] } sodiumoxide = "0.2.6" strum = "0.24.0" diff --git a/lib/dal/src/migrations/U0061__attribute_value_payload_stored_procedure.sql b/lib/dal/src/migrations/U0061__attribute_value_payload_stored_procedure.sql index e8bd4ce1bd..8073a24ec3 100644 --- a/lib/dal/src/migrations/U0061__attribute_value_payload_stored_procedure.sql +++ b/lib/dal/src/migrations/U0061__attribute_value_payload_stored_procedure.sql @@ -1,7 +1,53 @@ -CREATE OR REPLACE FUNCTION attribute_value_list_payload_for_read_context_v1(this_tenancy jsonb, - this_visibility jsonb, - this_context jsonb, - this_prop_id bigint) +CREATE OR REPLACE FUNCTION attribute_value_id_for_prop_and_context_v1(this_tenancy jsonb, this_visibility jsonb, + this_context jsonb, this_prop_id bigint) + RETURNS bigint +AS +$$ +DECLARE + attribute_value_id bigint; +BEGIN + SELECT DISTINCT + ON ( + attribute_values.attribute_context_prop_id, + COALESCE(avbtav.belongs_to_id, -1), + COALESCE(attribute_values.key, '') + ) attribute_values.id + INTO STRICT attribute_value_id + FROM attribute_values + LEFT JOIN attribute_value_belongs_to_attribute_value AS avbtav + ON attribute_values.id = avbtav.object_id + AND in_tenancy_and_visible_v1(this_tenancy, this_visibility, avbtav) + INNER JOIN prop_many_to_many_schema_variants AS pmtmsv + ON attribute_values.attribute_context_prop_id = pmtmsv.left_object_id + AND in_tenancy_and_visible_v1(this_tenancy, this_visibility, pmtmsv) + WHERE in_tenancy_and_visible_v1(this_tenancy, this_visibility, attribute_values) + AND in_attribute_context_v1(this_context, + attribute_values.attribute_context_prop_id, + attribute_values.attribute_context_internal_provider_id, + attribute_values.attribute_context_external_provider_id, + attribute_values.attribute_context_schema_id, + attribute_values.attribute_context_schema_variant_id, + attribute_values.attribute_context_component_id, + attribute_values.attribute_context_system_id) + AND pmtmsv.right_object_id = this_prop_id + ORDER BY attribute_values.attribute_context_prop_id, COALESCE(avbtav.belongs_to_id, -1), + COALESCE(attribute_values.key, ''), attribute_values.visibility_change_set_pk DESC, + attribute_values.visibility_deleted_at DESC NULLS FIRST, + attribute_values.attribute_context_internal_provider_id DESC, + attribute_values.attribute_context_external_provider_id DESC, + attribute_values.attribute_context_schema_id DESC, + attribute_values.attribute_context_schema_variant_id DESC, + attribute_values.attribute_context_component_id DESC, attribute_values.attribute_context_system_id DESC; + + RETURN attribute_value_id; +END; +$$ LANGUAGE PLPGSQL; + +CREATE + OR REPLACE FUNCTION attribute_value_list_payload_for_read_context_v1(this_tenancy jsonb, + this_visibility jsonb, + this_context jsonb, + this_prop_id bigint) RETURNS TABLE ( parent_attribute_value_id bigint, @@ -15,122 +61,17 @@ DECLARE parent_attribute_value_id bigint; BEGIN -- Grab the initial AttributeValueId based on the PropId we were given. - EXECUTE - 'SELECT DISTINCT ON (' || - E'\n' || - ' attribute_values.attribute_context_prop_id,' || - E'\n' || - ' COALESCE(avbtav.belongs_to_id, -1),' || - E'\n' || - ' COALESCE(attribute_values.key, '''')' || - E'\n' || - ')' || - E'\n' || - ' attribute_values.id AS attribute_value_id' || - E'\n' || - 'FROM' || - E'\n' || - ' attribute_values' || - E'\n' || - ' LEFT JOIN attribute_value_belongs_to_attribute_value AS avbtav ON' || - E'\n' || - ' attribute_values.id = avbtav.object_id' || - E'\n' || - ' AND in_tenancy_v1($1, avbtav.tenancy_universal,' || - E'\n' || - ' avbtav.tenancy_billing_account_ids,' || - E'\n' || - ' avbtav.tenancy_organization_ids,' || - E'\n' || - ' avbtav.tenancy_workspace_ids)' || - E'\n' || - ' AND is_visible_v1($2, avbtav.visibility_change_set_pk,' || - E'\n' || - ' avbtav.visibility_deleted_at)' || - E'\n' || - ' INNER JOIN prop_many_to_many_schema_variants AS pmtmsv ON' || - E'\n' || - ' attribute_values.attribute_context_prop_id = pmtmsv.left_object_id' || - E'\n' || - ' AND in_tenancy_v1($1, pmtmsv.tenancy_universal,' || - E'\n' || - ' pmtmsv.tenancy_billing_account_ids,' || - E'\n' || - ' pmtmsv.tenancy_organization_ids,' || - E'\n' || - ' pmtmsv.tenancy_workspace_ids)' || - E'\n' || - ' AND is_visible_v1($2, pmtmsv.visibility_change_set_pk,' || - E'\n' || - ' pmtmsv.visibility_deleted_at)' || - E'\n' || - 'WHERE' || - E'\n' || - ' in_tenancy_v1($1, attribute_values.tenancy_universal,' || - E'\n' || - ' attribute_values.tenancy_billing_account_ids,' || - E'\n' || - ' attribute_values.tenancy_organization_ids,' || - E'\n' || - ' attribute_values.tenancy_workspace_ids)' || - E'\n' || - ' AND is_visible_v1($2, attribute_values.visibility_change_set_pk,' || - E'\n' || - ' attribute_values.visibility_deleted_at)' || - E'\n' || - ' AND in_attribute_context_v1($3, attribute_values.attribute_context_prop_id,' || - E'\n' || - ' attribute_values.attribute_context_internal_provider_id,' || - E'\n' || - ' attribute_values.attribute_context_external_provider_id,' || - E'\n' || - ' attribute_values.attribute_context_schema_id,' || - E'\n' || - ' attribute_values.attribute_context_schema_variant_id,' || - E'\n' || - ' attribute_values.attribute_context_component_id,' || - E'\n' || - ' attribute_values.attribute_context_system_id)' || - E'\n' || - ' AND pmtmsv.right_object_id = $4' || - E'\n' || - 'ORDER BY' || - E'\n' || - ' attribute_values.attribute_context_prop_id,' || - E'\n' || - ' COALESCE(avbtav.belongs_to_id, -1),' || - E'\n' || - ' COALESCE(attribute_values.key, ''''),' || - E'\n' || - ' attribute_values.visibility_change_set_pk DESC,' || - E'\n' || - ' attribute_values.visibility_deleted_at DESC NULLS FIRST,' || - E'\n' || - ' attribute_values.attribute_context_internal_provider_id DESC,' || - E'\n' || - ' attribute_values.attribute_context_external_provider_id DESC,' || - E'\n' || - ' attribute_values.attribute_context_schema_id DESC,' || - E'\n' || - ' attribute_values.attribute_context_schema_variant_id DESC,' || - E'\n' || - ' attribute_values.attribute_context_component_id DESC,' || - E'\n' || - ' attribute_values.attribute_context_system_id DESC' || - E'\n' - INTO STRICT parent_attribute_value_id - USING - this_tenancy, - this_visibility, - this_context, - this_prop_id; - - RETURN QUERY EXECUTE - 'SELECT * FROM attribute_value_list_payload_for_read_context_and_root_v1($1, $2, $3, $4)' - USING - this_tenancy, - this_visibility, - this_context, - parent_attribute_value_id; + SELECT attribute_value_id_for_prop_and_context_v1( + this_tenancy, + this_visibility, + this_context, + this_prop_id + ) + INTO STRICT parent_attribute_value_id; + RETURN QUERY SELECT * + FROM attribute_value_list_payload_for_read_context_and_root_v1(this_tenancy, this_visibility, + this_context, + parent_attribute_value_id); END; -$$ LANGUAGE PLPGSQL; +$$ + LANGUAGE PLPGSQL;