@@ -5,20 +5,20 @@ import { getGitHubReposFromConfig } from "./github.js";
55import { getGitLabReposFromConfig } from "./gitlab.js" ;
66import { getGiteaReposFromConfig } from "./gitea.js" ;
77import { getGerritReposFromConfig } from "./gerrit.js" ;
8- import { AppContext , LocalRepository , GitRepository , Repository } from "./types.js" ;
8+ import { AppContext , LocalRepository , GitRepository , Repository , Settings } from "./types.js" ;
99import { cloneRepository , fetchRepository } from "./git.js" ;
1010import { createLogger } from "./logger.js" ;
11- import { createRepository , Database , loadDB , updateRepository } from './db.js' ;
11+ import { createRepository , Database , loadDB , updateRepository , updateSettings } from './db.js' ;
1212import { 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" ;
1414import stripJsonComments from 'strip-json-comments' ;
1515import { indexGitRepository , indexLocalRepository } from "./zoekt.js" ;
1616import { getLocalRepoFromConfig , initLocalRepoFileWatchers } from "./local.js" ;
1717import { captureEvent } from "./posthog.js" ;
1818
1919const logger = createLogger ( 'main' ) ;
2020
21- const syncGitRepository = async ( repo : GitRepository , ctx : AppContext ) => {
21+ const syncGitRepository = async ( repo : GitRepository , settings : Settings , ctx : AppContext ) => {
2222 let fetchDuration_s : number | undefined = undefined ;
2323 let cloneDuration_s : number | undefined = undefined ;
2424
@@ -46,7 +46,7 @@ const syncGitRepository = async (repo: GitRepository, ctx: AppContext) => {
4646 }
4747
4848 logger . info ( `Indexing ${ repo . id } ...` ) ;
49- const { durationMs } = await measure ( ( ) => indexGitRepository ( repo , ctx ) ) ;
49+ const { durationMs } = await measure ( ( ) => indexGitRepository ( repo , settings , ctx ) ) ;
5050 const indexDuration_s = durationMs / 1000 ;
5151 logger . info ( `Indexed ${ repo . id } in ${ indexDuration_s } s` ) ;
5252
@@ -57,18 +57,21 @@ const syncGitRepository = async (repo: GitRepository, ctx: AppContext) => {
5757 }
5858}
5959
60- const syncLocalRepository = async ( repo : LocalRepository , ctx : AppContext , signal ?: AbortSignal ) => {
60+ const syncLocalRepository = async ( repo : LocalRepository , settings : Settings , ctx : AppContext , signal ?: AbortSignal ) => {
6161 logger . info ( `Indexing ${ repo . id } ...` ) ;
62- const { durationMs } = await measure ( ( ) => indexLocalRepository ( repo , ctx , signal ) ) ;
62+ const { durationMs } = await measure ( ( ) => indexLocalRepository ( repo , settings , ctx , signal ) ) ;
6363 const indexDuration_s = durationMs / 1000 ;
6464 logger . info ( `Indexed ${ repo . id } in ${ indexDuration_s } s` ) ;
6565 return {
6666 indexDuration_s,
6767 }
6868}
6969
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 ) => {
7275 /**
7376 * Checks if the any of the `revisions` properties have changed.
7477 */
@@ -100,6 +103,16 @@ export const isRepoReindxingRequired = (previous: Repository, current: Repositor
100103 )
101104}
102105
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+
103116const syncConfig = async ( configPath : string , db : Database , signal : AbortSignal , ctx : AppContext ) => {
104117 const configContent = await ( async ( ) => {
105118 if ( isRemotePath ( configPath ) ) {
@@ -121,6 +134,13 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
121134 // @todo : we should validate the configuration file's structure here.
122135 const config = JSON . parse ( stripJsonComments ( configContent ) ) as SourcebotConfigurationSchema ;
123136
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+
124144 // Fetch all repositories from the config file
125145 let configRepos : Repository [ ] = [ ] ;
126146 for ( const repoConfig of config . repos ?? [ ] ) {
@@ -172,7 +192,7 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
172192 for ( const newRepo of configRepos ) {
173193 if ( newRepo . id in db . data . repos ) {
174194 const existingRepo = db . data . repos [ newRepo . id ] ;
175- const isReindexingRequired = isRepoReindxingRequired ( existingRepo , newRepo ) ;
195+ const isReindexingRequired = _isAllRepoReindexingRequired || isRepoReindexingRequired ( existingRepo , newRepo ) ;
176196 if ( isReindexingRequired ) {
177197 logger . info ( `Marking ${ newRepo . id } for reindexing due to configuration change.` ) ;
178198 }
@@ -244,7 +264,7 @@ export const main = async (context: AppContext) => {
244264 const localRepos = Object . values ( db . data . repos ) . filter ( repo => repo . vcs === 'local' ) ;
245265 initLocalRepoFileWatchers ( localRepos , async ( repo , signal ) => {
246266 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 ) ;
248268 await db . update ( ( { repos } ) => repos [ repo . id ] . lastIndexedDate = new Date ( ) . toUTCString ( ) ) ;
249269 } ) ;
250270 }
@@ -285,12 +305,12 @@ export const main = async (context: AppContext) => {
285305 let cloneDuration_s : number | undefined ;
286306
287307 if ( repo . vcs === 'git' ) {
288- const stats = await syncGitRepository ( repo , context ) ;
308+ const stats = await syncGitRepository ( repo , db . data . settings , context ) ;
289309 indexDuration_s = stats . indexDuration_s ;
290310 fetchDuration_s = stats . fetchDuration_s ;
291311 cloneDuration_s = stats . cloneDuration_s ;
292312 } else if ( repo . vcs === 'local' ) {
293- const stats = await syncLocalRepository ( repo , context ) ;
313+ const stats = await syncLocalRepository ( repo , db . data . settings , context ) ;
294314 indexDuration_s = stats . indexDuration_s ;
295315 }
296316
0 commit comments