@@ -8,6 +8,7 @@ import { GithubService } from "src/github/service";
88import { LoggerService } from "src/logger/service" ;
99import { ProjectRepository } from "src/project/repository" ;
1010import { RepositoryRepository } from "src/repository/repository" ;
11+ import { SearchItem } from "src/search/types" ;
1112import { SearchService } from "src/search/service" ;
1213import { Service } from "typedi" ;
1314
@@ -69,16 +70,22 @@ export class DigestCron {
6970
7071 const projectsFromDataFolder = await this . dataService . listProjects ( ) ;
7172
73+ const projectSearchItems : SearchItem [ ] = [ ] ;
74+ const contributionSearchItems : SearchItem [ ] = [ ] ;
75+ const contributorSearchItems : SearchItem [ ] = [ ] ;
76+
7277 for ( const project of projectsFromDataFolder ) {
7378 const [ { id : projectId } ] = await this . projectsRepository . upsert ( {
7479 ...project ,
7580 runId,
7681 id : project . slug ,
7782 } ) ;
78- this . searchService . upsert ( "project" , {
79- id : project . slug . replace ( / [ . ] / g, "-" ) , // MeiliSearch doesn't allow dots in ids
83+ const sanitizedSlug = project . slug . replace ( / [ . ] / g, "-" ) ; // MeiliSearch doesn't allow dots in ids
84+ projectSearchItems . push ( {
85+ id : `${ runId } --${ sanitizedSlug } ` ,
8086 title : project . name ,
8187 type : "project" ,
88+ runId,
8289 } ) ;
8390
8491 let addedRepositoryCount = 0 ;
@@ -125,10 +132,11 @@ export class DigestCron {
125132 runId,
126133 id : `${ provider } -${ githubUser . login } ` ,
127134 } ) ;
128- this . searchService . upsert ( "contributor" , {
129- id : `${ provider } -${ githubUser . login } ` ,
135+ contributorSearchItems . push ( {
136+ id : `${ runId } -- ${ provider } -${ githubUser . login } ` ,
130137 title : githubUser . name || githubUser . login ,
131138 type : "contributor" ,
139+ runId,
132140 } ) ;
133141
134142 await this . contributorsRepository . upsertRelationWithRepository ( {
@@ -153,10 +161,11 @@ export class DigestCron {
153161 contributorId,
154162 id : `${ provider } -${ issue . id } ` ,
155163 } ) ;
156- this . searchService . upsert ( "contribution" , {
157- id : `${ provider } -${ issue . id } ` ,
164+ contributionSearchItems . push ( {
165+ id : `${ runId } -- ${ provider } -${ issue . id } ` ,
158166 title : issue . title ,
159167 type : "contribution" ,
168+ runId,
160169 } ) ;
161170 }
162171
@@ -213,6 +222,12 @@ export class DigestCron {
213222 await this . contributorsRepository . deleteAllButWithRunId ( runId ) ;
214223 await this . repositoriesRepository . deleteAllButWithRunId ( runId ) ;
215224 await this . projectsRepository . deleteAllButWithRunId ( runId ) ;
225+ await this . searchService . upsert ( "project" , projectSearchItems ) ;
226+ await this . searchService . upsert ( "contribution" , contributionSearchItems ) ;
227+ await this . searchService . upsert ( "contributor" , contributorSearchItems ) ;
228+ await this . searchService . deleteAllButWithRunId ( "project" , runId ) ;
229+ await this . searchService . deleteAllButWithRunId ( "contribution" , runId ) ;
230+ await this . searchService . deleteAllButWithRunId ( "contributor" , runId ) ;
216231 } catch ( error ) {
217232 captureException ( error , { tags : { type : "CRON" } } ) ;
218233 }
0 commit comments