@@ -9,6 +9,8 @@ module Share.Postgres.Search.DefinitionSearch.Queries
9
9
defNameCompletionSearch ,
10
10
definitionTokenSearch ,
11
11
definitionNameSearch ,
12
+ isRootIndexed ,
13
+ markRootAsIndexed ,
12
14
DefnNameSearchFilter (.. ),
13
15
-- Exported for logging/debugging
14
16
searchTokensToTsQuery ,
@@ -74,16 +76,37 @@ claimUnsynced = do
74
76
RETURNING chosen.release_id, chosen.root_namespace_hash_id, chosen.codebase_user_id
75
77
|]
76
78
79
+ isRootIndexed :: BranchHashId -> Transaction e Bool
80
+ isRootIndexed rootBranchHashId = do
81
+ queryExpect1Col
82
+ [sql |
83
+ SELECT EXISTS (
84
+ SELECT FROM indexed_definition_search_doc_roots
85
+ WHERE root_namespace_hash_id = #{rootBranchHashId}
86
+ )
87
+ |]
88
+
89
+ markRootAsIndexed :: BranchHashId -> Transaction e ()
90
+ markRootAsIndexed rootBranchHashId = do
91
+ execute_
92
+ [sql |
93
+ INSERT INTO indexed_definition_search_doc_roots(root_namespace_hash_id)
94
+ VALUES(#{rootBranchHashId})
95
+ ON CONFLICT DO NOTHING
96
+ |]
97
+ -- We don't return anything, so we can use `execute_` here.
98
+ pure ()
99
+
77
100
-- | Save definition documents to be indexed for search.
78
101
insertDefinitionDocuments :: [DefinitionDocument Name (Name , ShortHash )] -> Transaction e ()
79
102
insertDefinitionDocuments docs = pipelined $ do
80
103
let docsTable = docRow <$> docs
81
104
execute_ $
82
105
[sql |
83
- WITH docs(project_id, release_id , name, token_text, arity, tag, metadata) AS (
106
+ WITH docs(root_namespace_hash_id , name, token_text, arity, tag, metadata) AS (
84
107
SELECT * FROM ^{toTable docsTable}
85
- ) INSERT INTO global_definition_search_docs (project_id, release_id , name, search_tokens, arity, tag, metadata)
86
- SELECT d.project_id, d.release_id , d.name, tsvector(d.token_text::text), d.arity, d.tag::definition_tag, d.metadata
108
+ ) INSERT INTO scoped_definition_search_docs (root_namespace_hash_id , name, search_tokens, arity, tag, metadata)
109
+ SELECT d.root_namespace_hash_id , d.name, tsvector(d.token_text::text), d.arity, d.tag::definition_tag, d.metadata
87
110
FROM docs d
88
111
ON CONFLICT DO NOTHING
89
112
|]
@@ -120,15 +143,6 @@ copySearchDocumentsForRelease rootBranchHashId projectId releaseId = do
120
143
FROM scoped_definition_search_docs doc
121
144
WHERE doc.root_namespace_hash_id = #{rootBranchHashId}
122
145
|]
123
- -- Update the release id for the copied documents.
124
- execute_
125
- [sql |
126
- UPDATE global_definition_search_docs
127
- SET release_id = #{releaseId}
128
- WHERE root_namespace_hash_id = #{rootBranchHashId}
129
- AND project_id = #{projectId}
130
- AND release_id IS NULL
131
- |]
132
146
133
147
-- | Wipe out any rows for the given project, useful when re-indexing and we only want to
134
148
-- have records for the latest release.
0 commit comments