@@ -5,20 +5,20 @@ import { getGitHubReposFromConfig } from "./github.js";
5
5
import { getGitLabReposFromConfig } from "./gitlab.js" ;
6
6
import { getGiteaReposFromConfig } from "./gitea.js" ;
7
7
import { getGerritReposFromConfig } from "./gerrit.js" ;
8
- import { AppContext , LocalRepository , GitRepository , Repository } from "./types.js" ;
8
+ import { AppContext , LocalRepository , GitRepository , Repository , Settings } from "./types.js" ;
9
9
import { cloneRepository , fetchRepository } from "./git.js" ;
10
10
import { createLogger } from "./logger.js" ;
11
- import { createRepository , Database , loadDB , updateRepository } from './db.js' ;
11
+ import { createRepository , Database , loadDB , updateRepository , updateSettings } from './db.js' ;
12
12
import { arraysEqualShallow , isRemotePath , measure } from "./utils.js" ;
13
- import { REINDEX_INTERVAL_MS , RESYNC_CONFIG_INTERVAL_MS } from "./constants.js" ;
13
+ import { DEFAULT_SETTINGS , REINDEX_INTERVAL_MS , RESYNC_CONFIG_INTERVAL_MS } from "./constants.js" ;
14
14
import stripJsonComments from 'strip-json-comments' ;
15
15
import { indexGitRepository , indexLocalRepository } from "./zoekt.js" ;
16
16
import { getLocalRepoFromConfig , initLocalRepoFileWatchers } from "./local.js" ;
17
17
import { captureEvent } from "./posthog.js" ;
18
18
19
19
const logger = createLogger ( 'main' ) ;
20
20
21
- const syncGitRepository = async ( repo : GitRepository , ctx : AppContext ) => {
21
+ const syncGitRepository = async ( repo : GitRepository , settings : Settings , ctx : AppContext ) => {
22
22
let fetchDuration_s : number | undefined = undefined ;
23
23
let cloneDuration_s : number | undefined = undefined ;
24
24
@@ -46,7 +46,7 @@ const syncGitRepository = async (repo: GitRepository, ctx: AppContext) => {
46
46
}
47
47
48
48
logger . info ( `Indexing ${ repo . id } ...` ) ;
49
- const { durationMs } = await measure ( ( ) => indexGitRepository ( repo , ctx ) ) ;
49
+ const { durationMs } = await measure ( ( ) => indexGitRepository ( repo , settings , ctx ) ) ;
50
50
const indexDuration_s = durationMs / 1000 ;
51
51
logger . info ( `Indexed ${ repo . id } in ${ indexDuration_s } s` ) ;
52
52
@@ -57,18 +57,21 @@ const syncGitRepository = async (repo: GitRepository, ctx: AppContext) => {
57
57
}
58
58
}
59
59
60
- const syncLocalRepository = async ( repo : LocalRepository , ctx : AppContext , signal ?: AbortSignal ) => {
60
+ const syncLocalRepository = async ( repo : LocalRepository , settings : Settings , ctx : AppContext , signal ?: AbortSignal ) => {
61
61
logger . info ( `Indexing ${ repo . id } ...` ) ;
62
- const { durationMs } = await measure ( ( ) => indexLocalRepository ( repo , ctx , signal ) ) ;
62
+ const { durationMs } = await measure ( ( ) => indexLocalRepository ( repo , settings , ctx , signal ) ) ;
63
63
const indexDuration_s = durationMs / 1000 ;
64
64
logger . info ( `Indexed ${ repo . id } in ${ indexDuration_s } s` ) ;
65
65
return {
66
66
indexDuration_s,
67
67
}
68
68
}
69
69
70
- export const isRepoReindxingRequired = ( previous : Repository , current : Repository ) => {
71
-
70
+ /**
71
+ * Certain configuration changes (e.g., a branch is added) require
72
+ * a reindexing of the repository.
73
+ */
74
+ export const isRepoReindexingRequired = ( previous : Repository , current : Repository ) => {
72
75
/**
73
76
* Checks if the any of the `revisions` properties have changed.
74
77
*/
@@ -100,6 +103,16 @@ export const isRepoReindxingRequired = (previous: Repository, current: Repositor
100
103
)
101
104
}
102
105
106
+ /**
107
+ * Certain settings changes (e.g., the file limit size is changed) require
108
+ * a reindexing of _all_ repositories.
109
+ */
110
+ export const isAllRepoReindexingRequired = ( previous : Settings , current : Settings ) => {
111
+ return (
112
+ previous ?. maxFileSize !== current ?. maxFileSize
113
+ )
114
+ }
115
+
103
116
const syncConfig = async ( configPath : string , db : Database , signal : AbortSignal , ctx : AppContext ) => {
104
117
const configContent = await ( async ( ) => {
105
118
if ( isRemotePath ( configPath ) ) {
@@ -121,6 +134,13 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
121
134
// @todo : we should validate the configuration file's structure here.
122
135
const config = JSON . parse ( stripJsonComments ( configContent ) ) as SourcebotConfigurationSchema ;
123
136
137
+ // Update the settings
138
+ const updatedSettings : Settings = {
139
+ maxFileSize : config . settings ?. maxFileSize ?? DEFAULT_SETTINGS . maxFileSize ,
140
+ }
141
+ const _isAllRepoReindexingRequired = isAllRepoReindexingRequired ( db . data . settings , updatedSettings ) ;
142
+ await updateSettings ( updatedSettings , db ) ;
143
+
124
144
// Fetch all repositories from the config file
125
145
let configRepos : Repository [ ] = [ ] ;
126
146
for ( const repoConfig of config . repos ?? [ ] ) {
@@ -172,7 +192,7 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
172
192
for ( const newRepo of configRepos ) {
173
193
if ( newRepo . id in db . data . repos ) {
174
194
const existingRepo = db . data . repos [ newRepo . id ] ;
175
- const isReindexingRequired = isRepoReindxingRequired ( existingRepo , newRepo ) ;
195
+ const isReindexingRequired = _isAllRepoReindexingRequired || isRepoReindexingRequired ( existingRepo , newRepo ) ;
176
196
if ( isReindexingRequired ) {
177
197
logger . info ( `Marking ${ newRepo . id } for reindexing due to configuration change.` ) ;
178
198
}
@@ -244,7 +264,7 @@ export const main = async (context: AppContext) => {
244
264
const localRepos = Object . values ( db . data . repos ) . filter ( repo => repo . vcs === 'local' ) ;
245
265
initLocalRepoFileWatchers ( localRepos , async ( repo , signal ) => {
246
266
logger . info ( `Change detected to local repository ${ repo . id } . Re-syncing...` ) ;
247
- await syncLocalRepository ( repo , context , signal ) ;
267
+ await syncLocalRepository ( repo , db . data . settings , context , signal ) ;
248
268
await db . update ( ( { repos } ) => repos [ repo . id ] . lastIndexedDate = new Date ( ) . toUTCString ( ) ) ;
249
269
} ) ;
250
270
}
@@ -285,12 +305,12 @@ export const main = async (context: AppContext) => {
285
305
let cloneDuration_s : number | undefined ;
286
306
287
307
if ( repo . vcs === 'git' ) {
288
- const stats = await syncGitRepository ( repo , context ) ;
308
+ const stats = await syncGitRepository ( repo , db . data . settings , context ) ;
289
309
indexDuration_s = stats . indexDuration_s ;
290
310
fetchDuration_s = stats . fetchDuration_s ;
291
311
cloneDuration_s = stats . cloneDuration_s ;
292
312
} else if ( repo . vcs === 'local' ) {
293
- const stats = await syncLocalRepository ( repo , context ) ;
313
+ const stats = await syncLocalRepository ( repo , db . data . settings , context ) ;
294
314
indexDuration_s = stats . indexDuration_s ;
295
315
}
296
316
0 commit comments