Skip to content

Commit

Permalink
Add search logging
Browse files Browse the repository at this point in the history
  • Loading branch information
knpwrs committed Dec 31, 2024
1 parent 83c2164 commit 7260598
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions apps/web-next/src/__generated__/graphql-types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apps/web/src/__generated__/graphql-types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "search_log_entry" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"query" TEXT NOT NULL,
"params" JSONB NOT NULL DEFAULT '{}',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "search_log_entry_pkey" PRIMARY KEY ("id")
);
2 changes: 1 addition & 1 deletion services/gateway/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"
9 changes: 9 additions & 0 deletions services/gateway/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,12 @@ model UploadList {
@@unique([createdAt, id])
@@map("upload_list")
}

model SearchLogEntry {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
query String
params Json @default("{}")
createdAt DateTime @default(now()) @map("created_at")
@@map("search_log_entry")
}
22 changes: 12 additions & 10 deletions services/gateway/src/schema/types/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,8 @@ builder.queryFields((t) => ({
},
),
},
resolve: async (
_root,
{
resolve: async (_root, args, context, _info) => {
const {
query,
focus,
channels,
Expand All @@ -287,11 +286,9 @@ builder.queryFields((t) => ({
orgType,
organization,
tags,
...args
},
context,
_info,
) => {
...restArgs
} = args;

let totalCount = 0;
let uploadHitCount = 0;
let transcriptHitCount = 0;
Expand All @@ -301,7 +298,7 @@ builder.queryFields((t) => ({
let dateAggData: { min: Date; max: Date } | null = null;

const publishedAt: { lte?: string; gte?: string } = {};
const orderBy = OrderByEnum.parse(args.orderBy ?? 'avg');
const orderBy = OrderByEnum.parse(restArgs.orderBy ?? 'avg');

if (minPublishedAt) {
publishedAt.gte =
Expand Down Expand Up @@ -345,7 +342,7 @@ builder.queryFields((t) => ({
: null;

const res = await resolveOffsetConnection(
{ args },
{ args: restArgs },
async ({ offset, limit }) => {
const esRes = await esClient.msearch({
searches: [
Expand Down Expand Up @@ -543,6 +540,11 @@ builder.queryFields((t) => ({
},
);

const { query: logQuery, ...logParams } = args;
await prisma.searchLogEntry.create({
data: { query: logQuery, params: logParams },
});

return {
...res,
totalCount,
Expand Down

0 comments on commit 7260598

Please sign in to comment.