Ejemplo n.º 1
0
        private RepositoryInformation ProcessSingleRepo(WritableRepositoryInformation repo)
        {
            if (_repoCache.TryGetCachedVersion(repo, out var cachedVersion))
            {
                return(cachedVersion);
            }

            using (_telemetry.TrackIndexRepositoryDuration(repo.Id))
                using (_logger.BeginScope("Starting indexing for repo {Name}", repo.Id))
                    using (var fetchedRepo = _repoFetcher.FetchRepo(repo))
                    {
                        IReadOnlyList <GitFileInfo> files;
                        using (_telemetry.TrackListFilesDuration(repo.Id))
                        {
                            _logger.LogInformation("Finding files in repo {Name}...", repo.Id);

                            files = fetchedRepo.GetFileInfos();
                        }

                        var filePaths = files.Where(ShouldCheckOutFile).Select(x => x.Path).ToList();

                        IReadOnlyList <ICheckedOutFile> checkedOutFiles;
                        using (_telemetry.TrackCheckOutFilesDuration(repo.Id))
                        {
                            _logger.LogInformation(
                                "Checking out {FileCount} files from repo {Name}",
                                filePaths.Count,
                                repo.Id);

                            checkedOutFiles = fetchedRepo.CheckoutFiles(filePaths);
                        }

                        foreach (var cfgFile in checkedOutFiles)
                        {
                            var dependencies = _configFileParser.Parse(cfgFile);
                            repo.AddDependencies(dependencies);
                        }

                        _logger.LogInformation("Finished indexing repo {Name}", repo.Id);
                    }

            var result = repo.ToRepositoryInformation();

            _repoCache.Persist(result);
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tries to read the cache file of a repository.
        /// </summary>
        /// <param name="repo">Repo to read the cache file for</param>
        /// <param name="cached">The read cached version or null if none has been created.</param>
        /// <returns>true if a cache file has been found and loaded.</returns>
        public bool TryGetCachedVersion(WritableRepositoryInformation repo, out RepositoryInformation cached)
        {
            var repoCacheFile = GetCachePath(repo.Id);

            _logger.LogInformation("Cache lookup for repo {RepoId}", repo.Id);
            if (!File.Exists(repoCacheFile))
            {
                cached = null;
                return(false);
            }

            _logger.LogInformation("Cache hit for repo {RepoId} on file {FileName}", repo.Id, repoCacheFile);
            repo.AddDependencies(JsonConvert.DeserializeObject <IReadOnlyList <string> >(File.ReadAllText(repoCacheFile)));
            cached = repo.ToRepositoryInformation();

            return(true);
        }