@@ -8,7 +8,6 @@ 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" ;
1211import { SearchService } from "src/search/service" ;
1312import { Service } from "typedi" ;
1413
@@ -70,23 +69,15 @@ export class DigestCron {
7069
7170 const projectsFromDataFolder = await this . dataService . listProjects ( ) ;
7271
73- const projectSearchItems : SearchItem [ ] = [ ] ;
74- const contributionSearchItems : SearchItem [ ] = [ ] ;
75- const contributorSearchItems : SearchItem [ ] = [ ] ;
76-
7772 for ( const project of projectsFromDataFolder ) {
78- const [ { id : projectId } ] = await this . projectsRepository . upsert ( {
73+ const projectEntity = {
7974 ...project ,
8075 runId,
81- id : project . slug ,
82- } ) ;
83- const sanitizedSlug = project . slug . replace ( / [ . ] / g, "-" ) ; // MeiliSearch doesn't allow dots in ids
84- projectSearchItems . push ( {
85- id : `${ runId } --${ sanitizedSlug } ` ,
86- title : project . name ,
87- type : "project" ,
88- runId,
89- } ) ;
76+ id : project . slug . replace ( / [ . ] / g, "-" ) , // MeiliSearch doesn't allow dots in ids,
77+ } ;
78+ const [ { id : projectId } ] =
79+ await this . projectsRepository . upsert ( projectEntity ) ;
80+ await this . searchService . upsert ( "project" , projectEntity ) ;
9081
9182 let addedRepositoryCount = 0 ;
9283 try {
@@ -123,21 +114,18 @@ export class DigestCron {
123114
124115 if ( githubUser . type !== "User" ) continue ;
125116
126- const [ { id : contributorId } ] =
127- await this . contributorsRepository . upsert ( {
128- name : githubUser . name || githubUser . login ,
129- username : githubUser . login ,
130- url : githubUser . html_url ,
131- avatarUrl : githubUser . avatar_url ,
132- runId,
133- id : `${ provider } -${ githubUser . login } ` ,
134- } ) ;
135- contributorSearchItems . push ( {
136- id : `${ runId } --${ provider } -${ githubUser . login } ` ,
137- title : githubUser . name || githubUser . login ,
138- type : "contributor" ,
117+ const contributorEntity = {
118+ name : githubUser . name || githubUser . login ,
119+ username : githubUser . login ,
120+ url : githubUser . html_url ,
121+ avatarUrl : githubUser . avatar_url ,
139122 runId,
140- } ) ;
123+ id : `${ provider } -${ githubUser . login } ` ,
124+ } ;
125+
126+ const [ { id : contributorId } ] =
127+ await this . contributorsRepository . upsert ( contributorEntity ) ;
128+ await this . searchService . upsert ( "contributor" , contributorEntity ) ;
141129
142130 await this . contributorsRepository . upsertRelationWithRepository ( {
143131 contributorId,
@@ -147,7 +135,7 @@ export class DigestCron {
147135 } ) ;
148136
149137 const type = issue . pull_request ? "PULL_REQUEST" : "ISSUE" ;
150- await this . contributionsRepository . upsert ( {
138+ const contributionEntity = {
151139 title : issue . title ,
152140 type,
153141 updatedAt : issue . updated_at ,
@@ -160,13 +148,12 @@ export class DigestCron {
160148 repositoryId,
161149 contributorId,
162150 id : `${ provider } -${ issue . id } ` ,
163- } ) ;
164- contributionSearchItems . push ( {
165- id : `${ runId } --${ provider } -${ issue . id } ` ,
166- title : issue . title ,
167- type : "contribution" ,
168- runId,
169- } ) ;
151+ } as const ;
152+ await this . contributionsRepository . upsert ( contributionEntity ) ;
153+ await this . searchService . upsert (
154+ "contribution" ,
155+ contributionEntity ,
156+ ) ;
170157 }
171158
172159 const repoContributors =
@@ -222,9 +209,6 @@ export class DigestCron {
222209 await this . contributorsRepository . deleteAllButWithRunId ( runId ) ;
223210 await this . repositoriesRepository . deleteAllButWithRunId ( runId ) ;
224211 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 ) ;
228212 await this . searchService . deleteAllButWithRunId ( "project" , runId ) ;
229213 await this . searchService . deleteAllButWithRunId ( "contribution" , runId ) ;
230214 await this . searchService . deleteAllButWithRunId ( "contributor" , runId ) ;
0 commit comments