From 820074b1d116ebb5b1c49c504e1020147cb5ebaf Mon Sep 17 00:00:00 2001 From: Simon Taggart Date: Thu, 1 Feb 2024 16:33:49 -0800 Subject: [PATCH] chore: better filtering of test search queries for more accurate data (#3752) * chore: better filtering of test search queries for more accurate data * chore: upgrade supabase cli client * chore: db types * chore: db types with updated supabase --- apps/backend/package.json | 2 +- .../20240201004610_top_searches_filtering.sql | 28 ++++ apps/backend/supabase/schema.gen.ts | 99 ++++++++++- .../api/discussions-search.spec.ts | 2 +- cypress/integration/api/docs-search.spec.ts | 2 +- .../api/paste-assistant-message.spec.ts | 10 +- cypress/integration/site-search/index.spec.ts | 2 +- yarn.lock | 158 ++---------------- 8 files changed, 146 insertions(+), 157 deletions(-) create mode 100644 apps/backend/supabase/migrations/20240201004610_top_searches_filtering.sql diff --git a/apps/backend/package.json b/apps/backend/package.json index afc7c8caae..d9d06a8c43 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -8,6 +8,6 @@ "generate:db-types": "yarn supabase gen types typescript --local > supabase/schema.gen.ts" }, "devDependencies": { - "supabase": "^1.99.5" + "supabase": "^1.136.3" } } diff --git a/apps/backend/supabase/migrations/20240201004610_top_searches_filtering.sql b/apps/backend/supabase/migrations/20240201004610_top_searches_filtering.sql new file mode 100644 index 0000000000..9d82e75888 --- /dev/null +++ b/apps/backend/supabase/migrations/20240201004610_top_searches_filtering.sql @@ -0,0 +1,28 @@ +set check_function_bodies = off; + +CREATE OR REPLACE FUNCTION public.match_weekly_search_usage() + RETURNS TABLE(query_string character varying, count bigint) + LANGUAGE plpgsql +AS $function$ +begin + return query + SELECT + queries.query_string, + count(*) as count + FROM + queries + WHERE + type = 'docs-search' + AND queries.query_string != 'dsys' + AND queries.query_string != 'this is a search test' + AND queries.created_at >= now() - interval '1 week' + GROUP BY + queries.query_string + ORDER BY + count DESC + LIMIT 20; +end; +$function$ +; + + diff --git a/apps/backend/supabase/schema.gen.ts b/apps/backend/supabase/schema.gen.ts index b1920e810f..3e217fb3fd 100644 --- a/apps/backend/supabase/schema.gen.ts +++ b/apps/backend/supabase/schema.gen.ts @@ -72,6 +72,7 @@ export interface Database { { foreignKeyName: "page_parent_page_id_fkey" columns: ["parent_page_id"] + isOneToOne: false referencedRelation: "page" referencedColumns: ["id"] } @@ -109,6 +110,7 @@ export interface Database { { foreignKeyName: "page_section_page_id_fkey" columns: ["page_id"] + isOneToOne: false referencedRelation: "page" referencedColumns: ["id"] } @@ -191,6 +193,7 @@ export interface Database { { foreignKeyName: "story_render_story_id_fkey" columns: ["story_id"] + isOneToOne: false referencedRelation: "story" referencedColumns: ["id"] } @@ -363,6 +366,7 @@ export interface Database { id: string name: string owner: string | null + owner_id: string | null public: boolean | null updated_at: string | null } @@ -374,6 +378,7 @@ export interface Database { id: string name: string owner?: string | null + owner_id?: string | null public?: boolean | null updated_at?: string | null } @@ -385,17 +390,11 @@ export interface Database { id?: string name?: string owner?: string | null + owner_id?: string | null public?: boolean | null updated_at?: string | null } - Relationships: [ - { - foreignKeyName: "buckets_owner_fkey" - columns: ["owner"] - referencedRelation: "users" - referencedColumns: ["id"] - } - ] + Relationships: [] } migrations: { Row: { @@ -427,6 +426,7 @@ export interface Database { metadata: Json | null name: string | null owner: string | null + owner_id: string | null path_tokens: string[] | null updated_at: string | null version: string | null @@ -439,6 +439,7 @@ export interface Database { metadata?: Json | null name?: string | null owner?: string | null + owner_id?: string | null path_tokens?: string[] | null updated_at?: string | null version?: string | null @@ -451,6 +452,7 @@ export interface Database { metadata?: Json | null name?: string | null owner?: string | null + owner_id?: string | null path_tokens?: string[] | null updated_at?: string | null version?: string | null @@ -459,6 +461,7 @@ export interface Database { { foreignKeyName: "objects_bucketId_fkey" columns: ["bucket_id"] + isOneToOne: false referencedRelation: "buckets" referencedColumns: ["id"] } @@ -533,3 +536,83 @@ export interface Database { } } +export type Tables< + PublicTableNameOrOptions extends + | keyof (Database["public"]["Tables"] & Database["public"]["Views"]) + | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } + ? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] & + Database[PublicTableNameOrOptions["schema"]]["Views"]) + : never = never +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? (Database[PublicTableNameOrOptions["schema"]]["Tables"] & + Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends { + Row: infer R + } + ? R + : never + : PublicTableNameOrOptions extends keyof (Database["public"]["Tables"] & + Database["public"]["Views"]) + ? (Database["public"]["Tables"] & + Database["public"]["Views"])[PublicTableNameOrOptions] extends { + Row: infer R + } + ? R + : never + : never + +export type TablesInsert< + PublicTableNameOrOptions extends + | keyof Database["public"]["Tables"] + | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } + ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] + : never = never +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends { + Insert: infer I + } + ? I + : never + : PublicTableNameOrOptions extends keyof Database["public"]["Tables"] + ? Database["public"]["Tables"][PublicTableNameOrOptions] extends { + Insert: infer I + } + ? I + : never + : never + +export type TablesUpdate< + PublicTableNameOrOptions extends + | keyof Database["public"]["Tables"] + | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } + ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] + : never = never +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends { + Update: infer U + } + ? U + : never + : PublicTableNameOrOptions extends keyof Database["public"]["Tables"] + ? Database["public"]["Tables"][PublicTableNameOrOptions] extends { + Update: infer U + } + ? U + : never + : never + +export type Enums< + PublicEnumNameOrOptions extends + | keyof Database["public"]["Enums"] + | { schema: keyof Database }, + EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database } + ? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"] + : never = never +> = PublicEnumNameOrOptions extends { schema: keyof Database } + ? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName] + : PublicEnumNameOrOptions extends keyof Database["public"]["Enums"] + ? Database["public"]["Enums"][PublicEnumNameOrOptions] + : never + diff --git a/cypress/integration/api/discussions-search.spec.ts b/cypress/integration/api/discussions-search.spec.ts index 177b0a60b3..92983d4794 100644 --- a/cypress/integration/api/discussions-search.spec.ts +++ b/cypress/integration/api/discussions-search.spec.ts @@ -1,6 +1,6 @@ context("GET /api/discussions-search", () => { it("gets a list of discussions", () => { - cy.request("POST", "/api/discussions-search", { prompt: "creating a button" }).then((response) => { + cy.request("POST", "/api/discussions-search", { prompt: "this is a search test" }).then((response) => { expect(response.status).to.eq(200); expect(response.body.data).length.to.be.greaterThan(1); }); diff --git a/cypress/integration/api/docs-search.spec.ts b/cypress/integration/api/docs-search.spec.ts index 02338fbd5f..eb5e51ebcd 100644 --- a/cypress/integration/api/docs-search.spec.ts +++ b/cypress/integration/api/docs-search.spec.ts @@ -1,6 +1,6 @@ context("GET /api/docs-search", () => { it("gets a list of docs", () => { - cy.request("POST", "/api/docs-search", { prompt: "creating a button" }).then((response) => { + cy.request("POST", "/api/docs-search", { prompt: "this is a search test" }).then((response) => { expect(response.status).to.eq(200); expect(response.body.data).length.to.be.greaterThan(1); }); diff --git a/cypress/integration/api/paste-assistant-message.spec.ts b/cypress/integration/api/paste-assistant-message.spec.ts index 3c1c8b578d..0a2dfbda5b 100644 --- a/cypress/integration/api/paste-assistant-message.spec.ts +++ b/cypress/integration/api/paste-assistant-message.spec.ts @@ -15,9 +15,11 @@ context("POST /api/paste-assistant-message", () => { it("creates an message on an ai thread", () => { // create a message on the thread - cy.request("POST", "/api/paste-assistant-message", { threadId, message: "create a button" }).then((response) => { - expect(response.status).to.eq(200); - }); + cy.request("POST", "/api/paste-assistant-message", { threadId, message: "this is a search test" }).then( + (response) => { + expect(response.status).to.eq(200); + }, + ); }); it("gets messages on an ai thread", () => { @@ -25,7 +27,7 @@ context("POST /api/paste-assistant-message", () => { cy.request("GET", `/api/paste-assistant-messages/${threadId}`).then((response) => { expect(response.status).to.eq(200); expect(response.body.data).length.to.be.greaterThan(0); - expect(response.body.data[0].content[0].text.value).to.eq("create a button"); + expect(response.body.data[0].content[0].text.value).to.eq("this is a search test"); }); }); }); diff --git a/cypress/integration/site-search/index.spec.ts b/cypress/integration/site-search/index.spec.ts index e3f08791a4..62e6b558c6 100644 --- a/cypress/integration/site-search/index.spec.ts +++ b/cypress/integration/site-search/index.spec.ts @@ -17,7 +17,7 @@ describe("Docs website search", () => { cy.get('[data-cy="paste-docsearch-input"]') .should("be.visible") .should("be.focused") - .type("checkbox") + .type("this is a search test") .type("{enter}"); cy.wait("@searchRequest"); cy.get('[data-cy="paste-docsearch-hits"] h2').should("have.length.above", 0); diff --git a/yarn.lock b/yarn.lock index bcca13a806..b92e3e2f31 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11083,13 +11083,6 @@ __metadata: languageName: node linkType: hard -"@tootallnate/quickjs-emscripten@npm:^0.23.0": - version: 0.23.0 - resolution: "@tootallnate/quickjs-emscripten@npm:0.23.0" - checksum: c350a2947ffb80b22e14ff35099fd582d1340d65723384a0fd0515e905e2534459ad2f301a43279a37308a27c99273c932e64649abd57d0bb3ca8c557150eccc - languageName: node - linkType: hard - "@trysound/sax@npm:0.2.0": version: 0.2.0 resolution: "@trysound/sax@npm:0.2.0" @@ -11475,7 +11468,7 @@ __metadata: version: 0.0.0-use.local resolution: "@twilio-paste/backend@workspace:apps/backend" dependencies: - supabase: ^1.99.5 + supabase: ^1.136.3 languageName: unknown linkType: soft @@ -18183,7 +18176,7 @@ __metadata: languageName: node linkType: hard -"agent-base@npm:^7.0.2, agent-base@npm:^7.1.0": +"agent-base@npm:^7.0.2": version: 7.1.0 resolution: "agent-base@npm:7.1.0" dependencies: @@ -19169,15 +19162,6 @@ __metadata: languageName: node linkType: hard -"ast-types@npm:^0.13.4": - version: 0.13.4 - resolution: "ast-types@npm:0.13.4" - dependencies: - tslib: ^2.0.1 - checksum: 5a51f7b70588ecced3601845a0e203279ca2f5fdc184416a0a1640c93ec0a267241d6090a328e78eebb8de81f8754754e0a4f1558ba2a3d638f8ccbd0b1f0eff - languageName: node - linkType: hard - "ast-types@npm:^0.16.1": version: 0.16.1 resolution: "ast-types@npm:0.16.1" @@ -19838,13 +19822,6 @@ __metadata: languageName: node linkType: hard -"basic-ftp@npm:^5.0.2": - version: 5.0.3 - resolution: "basic-ftp@npm:5.0.3" - checksum: 8b04e88eb85a64de9311721bb0707c9cd70453eefdd854cab85438e6f46fb6c597ddad57ed1acf0a9ede3c677b14e657f51051688a5f23d6f3ea7b5d9073b850 - languageName: node - linkType: hard - "batch@npm:0.6.1": version: 0.6.1 resolution: "batch@npm:0.6.1" @@ -19919,15 +19896,15 @@ __metadata: languageName: node linkType: hard -"bin-links@npm:^4.0.1": - version: 4.0.2 - resolution: "bin-links@npm:4.0.2" +"bin-links@npm:^4.0.3": + version: 4.0.3 + resolution: "bin-links@npm:4.0.3" dependencies: cmd-shim: ^6.0.0 npm-normalize-package-bin: ^3.0.0 read-cmd-shim: ^4.0.0 write-file-atomic: ^5.0.0 - checksum: 6f83e73100923b6c6bfb3e1b94bd981b3adf6d4b8e67609d0bec1efb5cfa2cf160ef5852335be42b8f8d3b0f15fae279c245cff7e3711d30b5be7f016408ec43 + checksum: 3b3ee22efc38d608479d51675c8958a841b8b55b8975342ce86f28ac4e0bb3aef46e9dbdde976c6dc1fe1bd2aa00d42e00869ad35b57ee6d868f39f662858911 languageName: node linkType: hard @@ -22746,13 +22723,6 @@ __metadata: languageName: node linkType: hard -"data-uri-to-buffer@npm:^5.0.1": - version: 5.0.1 - resolution: "data-uri-to-buffer@npm:5.0.1" - checksum: 10958f89c0047b84bd86d572b6b77c9bf238ebe7b55a9a9ab04c90fbf5ab1881783b72e31dc0febdffd30ec914930244f2f728e3629bb8911d922baba129426f - languageName: node - linkType: hard - "data-urls@npm:^3.0.2": version: 3.0.2 resolution: "data-urls@npm:3.0.2" @@ -23165,17 +23135,6 @@ __metadata: languageName: node linkType: hard -"degenerator@npm:^5.0.0": - version: 5.0.1 - resolution: "degenerator@npm:5.0.1" - dependencies: - ast-types: ^0.13.4 - escodegen: ^2.1.0 - esprima: ^4.0.1 - checksum: a64fa39cdf6c2edd75188157d32338ee9de7193d7dbb2aeb4acb1eb30fa4a15ed80ba8dae9bd4d7b085472cf174a5baf81adb761aaa8e326771392c922084152 - languageName: node - linkType: hard - "del@npm:^6.0.0": version: 6.0.0 resolution: "del@npm:6.0.0" @@ -26946,18 +26905,6 @@ fsevents@^1.2.7: languageName: node linkType: hard -"get-uri@npm:^6.0.1": - version: 6.0.1 - resolution: "get-uri@npm:6.0.1" - dependencies: - basic-ftp: ^5.0.2 - data-uri-to-buffer: ^5.0.1 - debug: ^4.3.4 - fs-extra: ^8.1.0 - checksum: a8aec70e1c67386fbe67f66e344ecd671a19f4cfc8e0f0e14d070563af5123d540e77fbceb6e26566f29846fac864d2862699ab134d307f85c85e7d72ce23d14 - languageName: node - linkType: hard - "get-value@npm:^2.0.3, get-value@npm:^2.0.6": version: 2.0.6 resolution: "get-value@npm:2.0.6" @@ -28387,16 +28334,6 @@ fsevents@^1.2.7: languageName: node linkType: hard -"http-proxy-agent@npm:^7.0.0": - version: 7.0.0 - resolution: "http-proxy-agent@npm:7.0.0" - dependencies: - agent-base: ^7.1.0 - debug: ^4.3.4 - checksum: 48d4fac997917e15f45094852b63b62a46d0c8a4f0b9c6c23ca26d27b8df8d178bed88389e604745e748bd9a01f5023e25093722777f0593c3f052009ff438b6 - languageName: node - linkType: hard - "http-proxy-middleware@npm:^2.0.0": version: 2.0.4 resolution: "http-proxy-middleware@npm:2.0.4" @@ -28983,7 +28920,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"ip@npm:^1.1.0, ip@npm:^1.1.8": +"ip@npm:^1.1.0": version: 1.1.8 resolution: "ip@npm:1.1.8" checksum: a2ade53eb339fb0cbe9e69a44caab10d6e3784662285eb5d2677117ee4facc33a64679051c35e0dfdb1a3983a51ce2f5d2cb36446d52e10d01881789b76e28fb @@ -32879,7 +32816,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"lru-cache@npm:^7.14.1, lru-cache@npm:^7.4.4, lru-cache@npm:^7.5.1, lru-cache@npm:^7.7.1": +"lru-cache@npm:^7.4.4, lru-cache@npm:^7.5.1, lru-cache@npm:^7.7.1": version: 7.18.3 resolution: "lru-cache@npm:7.18.3" checksum: e550d772384709deea3f141af34b6d4fa392e2e418c1498c078de0ee63670f1f46f5eee746e8ef7e69e1c895af0d4224e62ee33e66a543a14763b0f2e74c1356 @@ -34956,13 +34893,6 @@ fsevents@^1.2.7: languageName: node linkType: hard -"netmask@npm:^2.0.2": - version: 2.0.2 - resolution: "netmask@npm:2.0.2" - checksum: c65cb8d3f7ea5669edddb3217e4c96910a60d0d9a4b52d9847ff6b28b2d0277cd8464eee0ef85133cdee32605c57940cacdd04a9a019079b091b6bba4cb0ec22 - languageName: node - linkType: hard - "next-tick@npm:~1.0.0": version: 1.0.0 resolution: "next-tick@npm:1.0.0" @@ -35136,7 +35066,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"node-fetch@npm:^3.2.10": +"node-fetch@npm:^3.3.2": version: 3.3.2 resolution: "node-fetch@npm:3.3.2" dependencies: @@ -36526,33 +36456,6 @@ fsevents@^1.2.7: languageName: node linkType: hard -"pac-proxy-agent@npm:^7.0.1": - version: 7.0.1 - resolution: "pac-proxy-agent@npm:7.0.1" - dependencies: - "@tootallnate/quickjs-emscripten": ^0.23.0 - agent-base: ^7.0.2 - debug: ^4.3.4 - get-uri: ^6.0.1 - http-proxy-agent: ^7.0.0 - https-proxy-agent: ^7.0.2 - pac-resolver: ^7.0.0 - socks-proxy-agent: ^8.0.2 - checksum: 3d4aa48ec1c19db10158ecc1c4c9a9f77792294412d225ceb3dfa45d5a06950dca9755e2db0d9b69f12769119bea0adf2b24390d9c73c8d81df75e28245ae451 - languageName: node - linkType: hard - -"pac-resolver@npm:^7.0.0": - version: 7.0.0 - resolution: "pac-resolver@npm:7.0.0" - dependencies: - degenerator: ^5.0.0 - ip: ^1.1.8 - netmask: ^2.0.2 - checksum: fa3a898c09848e93e35f5e23443fea36ddb393a851c76a23664a5bf3fcbe58ff77a0bcdae1e4f01b9ea87ea493c52e14d97a0fe39f92474d14cd45559c6e3cde - languageName: node - linkType: hard - "package-hash@npm:^4.0.0": version: 4.0.0 resolution: "package-hash@npm:4.0.0" @@ -38601,22 +38504,6 @@ fsevents@^1.2.7: languageName: node linkType: hard -"proxy-agent@npm:^6.3.1": - version: 6.3.1 - resolution: "proxy-agent@npm:6.3.1" - dependencies: - agent-base: ^7.0.2 - debug: ^4.3.4 - http-proxy-agent: ^7.0.0 - https-proxy-agent: ^7.0.2 - lru-cache: ^7.14.1 - pac-proxy-agent: ^7.0.1 - proxy-from-env: ^1.1.0 - socks-proxy-agent: ^8.0.2 - checksum: 31030da419da31809340ac2521090c9a5bf4fe47a944843f829b3502883208c8586a468955e64b694140a41d70af6f45cf4793f5efd4a6f3ed94e5ac8023e36d - languageName: node - linkType: hard - "proxy-from-env@npm:1.0.0": version: 1.0.0 resolution: "proxy-from-env@npm:1.0.0" @@ -41647,18 +41534,7 @@ resolve@^2.0.0-next.3: languageName: node linkType: hard -"socks-proxy-agent@npm:^8.0.2": - version: 8.0.2 - resolution: "socks-proxy-agent@npm:8.0.2" - dependencies: - agent-base: ^7.0.2 - debug: ^4.3.4 - socks: ^2.7.1 - checksum: 4fb165df08f1f380881dcd887b3cdfdc1aba3797c76c1e9f51d29048be6e494c5b06d68e7aea2e23df4572428f27a3ec22b3d7c75c570c5346507433899a4b6d - languageName: node - linkType: hard - -"socks@npm:^2.3.3, socks@npm:^2.6.2, socks@npm:^2.7.1": +"socks@npm:^2.3.3, socks@npm:^2.6.2": version: 2.7.1 resolution: "socks@npm:2.7.1" dependencies: @@ -42703,17 +42579,17 @@ resolve@^2.0.0-next.3: languageName: node linkType: hard -"supabase@npm:^1.99.5": - version: 1.99.10 - resolution: "supabase@npm:1.99.10" +"supabase@npm:^1.136.3": + version: 1.141.0 + resolution: "supabase@npm:1.141.0" dependencies: - bin-links: ^4.0.1 - node-fetch: ^3.2.10 - proxy-agent: ^6.3.1 + bin-links: ^4.0.3 + https-proxy-agent: ^7.0.2 + node-fetch: ^3.3.2 tar: 6.2.0 bin: supabase: bin/supabase - checksum: dd3f292bb92706bbbdff39357aec10c2223eab8c13a46c4465c8d7d5988e6d71fd90090355d5a23f4721edc0c1b830a54493809710cc987a3b3cc79cd8e213f4 + checksum: d2104f307b118870274b313469f0463aa88d812fa57784ee964035f4fb65d83c0724cac0fd642823165f0065da84692da651372be693cc85229069240f236308 languageName: node linkType: hard