diff --git a/lib/develop/gittools/factory.v b/lib/develop/gittools/factory.v index 78abcd82..7e0e886e 100644 --- a/lib/develop/gittools/factory.v +++ b/lib/develop/gittools/factory.v @@ -39,7 +39,7 @@ pub fn new(args_ GitStructureArgsNew) !&GitStructure { } return gs }else{ - console.print_header("Loading GitStructure for ${args.coderoot}.") + console.print_debug("Loading GitStructure for ${args.coderoot}") } // Create and load the GitStructure instance. @@ -57,7 +57,7 @@ pub fn new(args_ GitStructureArgsNew) !&GitStructure { gs.config()! // will load the config, don't remove - if gs.repos.keys().len == 0 || args.reload { + if args.reload { gs.load(true)! }else{ gs.load(false)! diff --git a/lib/develop/gittools/gitstructure.v b/lib/develop/gittools/gitstructure.v index d2e0f97d..012805b1 100644 --- a/lib/develop/gittools/gitstructure.v +++ b/lib/develop/gittools/gitstructure.v @@ -43,6 +43,7 @@ pub fn (mut gitstructure GitStructure) load(reset bool) ! { for _, mut repo in gitstructure.repos { repo.status_update(reset: reset)! } + gitstructure.config_save()! } // Recursively loads repositories from the provided path, updating their statuses, does not check the status @@ -127,7 +128,7 @@ fn (mut gitstructure GitStructure) repo_init_from_path_(path string, params Repo // Retrieve GitLocation from the path. gl := gitstructure.gitlocation_from_path(mypath.path)! - console.print_debug("Initializing GitRepo from path: ${mypath.path}") + // console.print_debug("Initializing GitRepo from path: ${mypath.path}") // Initialize and return a GitRepo struct. mut r := GitRepo{ gs: &gitstructure diff --git a/lib/develop/gittools/gittools_do.v b/lib/develop/gittools/gittools_do.v index 602610c8..eead39b1 100644 --- a/lib/develop/gittools/gittools_do.v +++ b/lib/develop/gittools/gittools_do.v @@ -45,12 +45,10 @@ pub fn (mut gs GitStructure) do(args_ ReposActionsArgs) !string { mut args := args_ console.print_debug('git do ${args.cmd}') - $dbg; - - if args.path == '' && args.url == '' && args.repo == '' && args.account == '' - && args.provider == '' && args.filter == '' { - args.path = os.getwd() - } + // if args.path == '' && args.url == '' && args.repo == '' && args.account == '' + // && args.provider == '' && args.filter == '' { + // args.path = os.getwd() + // } if args.path != '' { mut curdiro := pathlib.get_dir(path: args.path, create: false)! @@ -83,8 +81,6 @@ pub fn (mut gs GitStructure) do(args_ ReposActionsArgs) !string { // gs.load(true)! // <-- REMOVED // } - // NEW: Update status only for the relevant repos. - console.print_header('Updating status for selected repos...') for mut repo in repos { repo.status_update(reset: args.reload || args.cmd == 'reload')! } diff --git a/lib/develop/gittools/repos_print.v b/lib/develop/gittools/repos_print.v index 78d2825a..35edcec5 100644 --- a/lib/develop/gittools/repos_print.v +++ b/lib/develop/gittools/repos_print.v @@ -57,7 +57,7 @@ pub fn (mut gitstructure GitStructure) repos_print(args ReposGetArgs) ! { console.clear() // console.print_lf(1) // Removed to reduce newlines - header := 'Repositories: ${gitstructure.coderoot}' + header := 'Repositories: ${gitstructure.coderoot.path}' console.print_header(header) console.print_lf(1) // Keep one newline after header diff --git a/lib/develop/gittools/repository_cache.v b/lib/develop/gittools/repository_cache.v index 483281bb..2a4044b8 100644 --- a/lib/develop/gittools/repository_cache.v +++ b/lib/develop/gittools/repository_cache.v @@ -13,6 +13,7 @@ fn (mut repo GitRepo) cache_set() ! { mut redis_client := redis_get() repo_json := json.encode(repo) cache_key := repo.cache_key() + // println("Caching repository ${repo.name} at ${cache_key}") redis_client.set(cache_key, repo_json)! } @@ -30,6 +31,16 @@ fn (mut repo GitRepo) cache_get() ! { } } +fn (mut repo GitRepo) cache_exists() !bool { + mut repo_json := '' + mut redis_client := redis_get() + cache_key := repo.cache_key() + // println("${repo.name} : Checking if cache exists at ${cache_key}") + repo_json = redis_client.get(cache_key) or { return false } + // println(repo_json) + return repo_json.len > 0 +} + // Remove cache fn (mut repo GitRepo) cache_delete() ! { mut redis_client := redis_get() diff --git a/lib/develop/gittools/repository_load.v b/lib/develop/gittools/repository_load.v index 3a6ec6b5..fae2b27b 100644 --- a/lib/develop/gittools/repository_load.v +++ b/lib/develop/gittools/repository_load.v @@ -18,25 +18,36 @@ pub fn (mut repo GitRepo) status_update(args StatusUpdateArgs) ! { return } + if args.reset || repo.last_load == 0 { + // console.print_debug('${repo.name} : Cache get') + repo.cache_get()! + } + + // cacheexists:=repo.cache_exists()! + // console.print_debug('${repo.name} : Checking if a full load is needed for cacheexists:${cacheexists} ') + current_time := int(time.now().unix()) // Decide if a full load is needed. if args.reset || repo.last_load == 0 || current_time - repo.last_load >= repo.config.remote_check_period { + $dbg; repo.load_internal() or { // Persist the error state to the cache + console.print_stderr('Failed to load repository ${repo.name} at ${repo.path()}: ${err}') if repo.status.error == '' { repo.status.error = 'Failed to load repository: ${err}' } - repo.cache_set()! return error('Failed to load repository ${repo.name}: ${err}') } + repo.cache_set()! + // $dbg; } } // load_internal performs the expensive git operations to refresh the repository state. // It should only be called by status_update(). fn (mut repo GitRepo) load_internal() ! { - console.print_header('load ${repo.print_key()}') + console.print_debug('load ${repo.print_key()}') repo.init()! repo.exec('git fetch --all') or { diff --git a/lib/develop/gittools/repository_model.v b/lib/develop/gittools/repository_model.v index eea2b57f..d1c3bcaa 100644 --- a/lib/develop/gittools/repository_model.v +++ b/lib/develop/gittools/repository_model.v @@ -38,21 +38,5 @@ pub mut: pub struct GitRepoConfig { pub mut: - remote_check_period int = 300 // seconds, 5 min + remote_check_period int = 3600 // seconds = 1h } - -// // just some initialization mechanism -// fn (mut gitstructure GitStructure) repo_new_from_gitlocation(git_location GitLocation) !&GitRepo { -// mut repo := GitRepo{ -// provider: git_location.provider -// name: git_location.name -// account: git_location.account -// gs: &gitstructure -// status_remote: GitRepoStatusRemote{} -// status_local: GitRepoStatusLocal{} -// status_wanted: GitRepoStatusWanted{} -// } -// gitstructure.repos[repo.cache_key()] = &repo - -// return &repo -// }