mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: wire chat search box to full-text search (#27973)
This commit is contained in:
@@ -1889,13 +1889,6 @@ func (q *querier) CalculateAIBridgeInterceptionsTelemetrySummary(ctx context.Con
|
||||
return q.db.CalculateAIBridgeInterceptionsTelemetrySummary(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) ChatSearchQueryIsEmpty(ctx context.Context, search string) (bool, error) {
|
||||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceChat); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return q.db.ChatSearchQueryIsEmpty(ctx, search)
|
||||
}
|
||||
|
||||
func (q *querier) ClaimPrebuiltWorkspace(ctx context.Context, arg database.ClaimPrebuiltWorkspaceParams) (database.ClaimPrebuiltWorkspaceRow, error) {
|
||||
empty := database.ClaimPrebuiltWorkspaceRow{}
|
||||
|
||||
|
||||
@@ -962,10 +962,6 @@ func (s *MethodTestSuite) TestChats() {
|
||||
dbm.EXPECT().BackfillChatMessagesSearchTsv(gomock.Any(), int32(100)).Return(int64(0), nil).AnyTimes()
|
||||
check.Args(int32(100)).Asserts(rbac.ResourceChat, policy.ActionUpdate)
|
||||
}))
|
||||
s.Run("ChatSearchQueryIsEmpty", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
|
||||
dbm.EXPECT().ChatSearchQueryIsEmpty(gomock.Any(), "!!!").Return(true, nil).AnyTimes()
|
||||
check.Args("!!!").Asserts(rbac.ResourceChat, policy.ActionRead)
|
||||
}))
|
||||
s.Run("GetChatRetentionDays", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
|
||||
dbm.EXPECT().GetChatRetentionDays(gomock.Any()).Return(int32(30), nil).AnyTimes()
|
||||
check.Args().Asserts()
|
||||
|
||||
-8
@@ -265,14 +265,6 @@ func (m queryMetricsStore) CalculateAIBridgeInterceptionsTelemetrySummary(ctx co
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
func (m queryMetricsStore) ChatSearchQueryIsEmpty(ctx context.Context, search string) (bool, error) {
|
||||
start := time.Now()
|
||||
r0, r1 := m.s.ChatSearchQueryIsEmpty(ctx, search)
|
||||
m.queryLatencies.WithLabelValues("ChatSearchQueryIsEmpty").Observe(time.Since(start).Seconds())
|
||||
m.queryCounts.WithLabelValues(httpmw.ExtractHTTPRoute(ctx), httpmw.ExtractHTTPMethod(ctx), "ChatSearchQueryIsEmpty").Inc()
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
func (m queryMetricsStore) ClaimPrebuiltWorkspace(ctx context.Context, arg database.ClaimPrebuiltWorkspaceParams) (database.ClaimPrebuiltWorkspaceRow, error) {
|
||||
start := time.Now()
|
||||
r0, r1 := m.s.ClaimPrebuiltWorkspace(ctx, arg)
|
||||
|
||||
Generated
-15
@@ -337,21 +337,6 @@ func (mr *MockStoreMockRecorder) CalculateAIBridgeInterceptionsTelemetrySummary(
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CalculateAIBridgeInterceptionsTelemetrySummary", reflect.TypeOf((*MockStore)(nil).CalculateAIBridgeInterceptionsTelemetrySummary), ctx, arg)
|
||||
}
|
||||
|
||||
// ChatSearchQueryIsEmpty mocks base method.
|
||||
func (m *MockStore) ChatSearchQueryIsEmpty(ctx context.Context, search string) (bool, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ChatSearchQueryIsEmpty", ctx, search)
|
||||
ret0, _ := ret[0].(bool)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ChatSearchQueryIsEmpty indicates an expected call of ChatSearchQueryIsEmpty.
|
||||
func (mr *MockStoreMockRecorder) ChatSearchQueryIsEmpty(ctx, search any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChatSearchQueryIsEmpty", reflect.TypeOf((*MockStore)(nil).ChatSearchQueryIsEmpty), ctx, search)
|
||||
}
|
||||
|
||||
// ClaimPrebuiltWorkspace mocks base method.
|
||||
func (m *MockStore) ClaimPrebuiltWorkspace(ctx context.Context, arg database.ClaimPrebuiltWorkspaceParams) (database.ClaimPrebuiltWorkspaceRow, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
Generated
-3
@@ -86,9 +86,6 @@ type sqlcQuerier interface {
|
||||
// Calculates the telemetry summary for a given provider, model, and client
|
||||
// combination for telemetry reporting.
|
||||
CalculateAIBridgeInterceptionsTelemetrySummary(ctx context.Context, arg CalculateAIBridgeInterceptionsTelemetrySummaryParams) (CalculateAIBridgeInterceptionsTelemetrySummaryRow, error)
|
||||
// Reports whether search text tokenizes to an empty tsquery (e.g. '!!!').
|
||||
// Used to reject input that would silently match nothing.
|
||||
ChatSearchQueryIsEmpty(ctx context.Context, search string) (bool, error)
|
||||
ClaimPrebuiltWorkspace(ctx context.Context, arg ClaimPrebuiltWorkspaceParams) (ClaimPrebuiltWorkspaceRow, error)
|
||||
CleanTailnetCoordinators(ctx context.Context) error
|
||||
CleanTailnetLostPeers(ctx context.Context) error
|
||||
|
||||
Generated
-13
@@ -6993,19 +6993,6 @@ func (q *sqlQuerier) BatchUpsertChatHeartbeats(ctx context.Context, arg BatchUps
|
||||
return err
|
||||
}
|
||||
|
||||
const chatSearchQueryIsEmpty = `-- name: ChatSearchQueryIsEmpty :one
|
||||
SELECT numnode(websearch_to_tsquery('simple', $1::text)) = 0 AS is_empty
|
||||
`
|
||||
|
||||
// Reports whether search text tokenizes to an empty tsquery (e.g. '!!!').
|
||||
// Used to reject input that would silently match nothing.
|
||||
func (q *sqlQuerier) ChatSearchQueryIsEmpty(ctx context.Context, search string) (bool, error) {
|
||||
row := q.db.QueryRowContext(ctx, chatSearchQueryIsEmpty, search)
|
||||
var is_empty bool
|
||||
err := row.Scan(&is_empty)
|
||||
return is_empty, err
|
||||
}
|
||||
|
||||
const countChatQueuedMessages = `-- name: CountChatQueuedMessages :one
|
||||
SELECT COUNT(*)::bigint AS count
|
||||
FROM chat_queued_messages
|
||||
|
||||
@@ -335,11 +335,6 @@ SET search_tsv = COALESCE(
|
||||
''::tsvector)
|
||||
FROM batch WHERE cm.id = batch.id;
|
||||
|
||||
-- name: ChatSearchQueryIsEmpty :one
|
||||
-- Reports whether search text tokenizes to an empty tsquery (e.g. '!!!').
|
||||
-- Used to reject input that would silently match nothing.
|
||||
SELECT numnode(websearch_to_tsquery('simple', @search::text)) = 0 AS is_empty;
|
||||
|
||||
-- name: GetChatByID :one
|
||||
SELECT *
|
||||
FROM chats_expanded
|
||||
|
||||
Reference in New Issue
Block a user