mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-15 13:55:20 +00:00
Add some instrumentation to web
This commit is contained in:
parent
d70b729ee8
commit
ce52f651be
3 changed files with 52 additions and 12 deletions
|
|
@ -10,7 +10,7 @@ import useCaptureEvent from "@/hooks/useCaptureEvent";
|
||||||
import { useNonEmptyQueryParam } from "@/hooks/useNonEmptyQueryParam";
|
import { useNonEmptyQueryParam } from "@/hooks/useNonEmptyQueryParam";
|
||||||
import { useSearchHistory } from "@/hooks/useSearchHistory";
|
import { useSearchHistory } from "@/hooks/useSearchHistory";
|
||||||
import { Repository, SearchQueryParams, SearchResultFile } from "@/lib/types";
|
import { Repository, SearchQueryParams, SearchResultFile } from "@/lib/types";
|
||||||
import { createPathWithQueryParams } from "@/lib/utils";
|
import { createPathWithQueryParams, measureSync } from "@/lib/utils";
|
||||||
import { SymbolIcon } from "@radix-ui/react-icons";
|
import { SymbolIcon } from "@radix-ui/react-icons";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
@ -139,16 +139,19 @@ const SearchPageInternal = () => {
|
||||||
|
|
||||||
// We only want to show matches for the default branch when
|
// We only want to show matches for the default branch when
|
||||||
// the user isn't explicitly filtering by branch.
|
// the user isn't explicitly filtering by branch.
|
||||||
if (!isBranchFilteringEnabled) {
|
|
||||||
fileMatches = fileMatches.filter(match => {
|
|
||||||
// @note : this case handles local repos that don't have any branches.
|
|
||||||
if (!match.Branches) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return match.Branches.includes("HEAD");
|
measureSync(() => {
|
||||||
});
|
if (!isBranchFilteringEnabled) {
|
||||||
}
|
fileMatches = fileMatches.filter(match => {
|
||||||
|
// @note : this case handles local repos that don't have any branches.
|
||||||
|
if (!match.Branches) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match.Branches.includes("HEAD");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, "search.branchFiltering");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fileMatches,
|
fileMatches,
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,19 @@
|
||||||
import { NEXT_PUBLIC_DOMAIN_SUB_PATH } from "@/lib/environment.client";
|
import { NEXT_PUBLIC_DOMAIN_SUB_PATH } from "@/lib/environment.client";
|
||||||
import { fileSourceResponseSchema, listRepositoriesResponseSchema, searchResponseSchema } from "@/lib/schemas";
|
import { fileSourceResponseSchema, listRepositoriesResponseSchema, searchResponseSchema } from "@/lib/schemas";
|
||||||
import { FileSourceRequest, FileSourceResponse, ListRepositoriesResponse, SearchRequest, SearchResponse } from "@/lib/types";
|
import { FileSourceRequest, FileSourceResponse, ListRepositoriesResponse, SearchRequest, SearchResponse } from "@/lib/types";
|
||||||
|
import { measure } from "@/lib/utils";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
export const search = async (body: SearchRequest, domain: string): Promise<SearchResponse> => {
|
export const search = async (body: SearchRequest, domain: string): Promise<SearchResponse> => {
|
||||||
const path = resolveServerPath("/api/search");
|
const path = resolveServerPath("/api/search");
|
||||||
const result = await fetch(path, {
|
const { data: result } = await measure(() => fetch(path, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-Org-Domain": domain,
|
"X-Org-Domain": domain,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
}).then(response => response.json());
|
}).then(response => response.json()), "client.search");
|
||||||
|
|
||||||
return searchResponseSchema.parse(result);
|
return searchResponseSchema.parse(result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -208,3 +208,39 @@ export const getDisplayTime = (date: Date) => {
|
||||||
return formatTime(months, 'month');
|
return formatTime(months, 'month');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const measureSync = <T>(cb: () => T, measureName: string) => {
|
||||||
|
const startMark = `${measureName}.start`;
|
||||||
|
const endMark = `${measureName}.end`;
|
||||||
|
|
||||||
|
performance.mark(startMark);
|
||||||
|
const data = cb();
|
||||||
|
performance.mark(endMark);
|
||||||
|
|
||||||
|
const measure = performance.measure(measureName, startMark, endMark);
|
||||||
|
const durationMs = measure.duration;
|
||||||
|
console.debug(`[${measureName}] took ${durationMs}ms`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
durationMs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const measure = async <T>(cb: () => Promise<T>, measureName: string) => {
|
||||||
|
const startMark = `${measureName}.start`;
|
||||||
|
const endMark = `${measureName}.end`;
|
||||||
|
|
||||||
|
performance.mark(startMark);
|
||||||
|
const data = await cb();
|
||||||
|
performance.mark(endMark);
|
||||||
|
|
||||||
|
const measure = performance.measure(measureName, startMark, endMark);
|
||||||
|
const durationMs = measure.duration;
|
||||||
|
console.debug(`[${measureName}] took ${durationMs}ms`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
durationMs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue