diff options
author | zeripath <art27@cantab.net> | 2022-01-19 23:26:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-19 23:26:57 +0000 |
commit | 5cb0c9aa0d7eed087055b1efca79628957207d36 (patch) | |
tree | d117a514e1f17e5f6bfcda1be273f6a971112663 /modules/indexer/code/indexer.go | |
parent | 4563148a61ba892e8f2bb66342f00a950bcd5315 (diff) | |
download | gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip |
Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git
commands run within the request context.
This now means that the if there is a git repo already open in the context it will be used instead of reopening it.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/indexer/code/indexer.go')
-rw-r--r-- | modules/indexer/code/indexer.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/modules/indexer/code/indexer.go b/modules/indexer/code/indexer.go index a616d0e662..a17484cae5 100644 --- a/modules/indexer/code/indexer.go +++ b/modules/indexer/code/indexer.go @@ -42,7 +42,7 @@ type SearchResultLanguages struct { // Indexer defines an interface to index and search code contents type Indexer interface { - Index(repo *repo_model.Repository, sha string, changes *repoChanges) error + Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *repoChanges) error Delete(repoID int64) error Search(repoIDs []int64, language, keyword string, page, pageSize int, isMatch bool) (int64, []*SearchResult, []*SearchResultLanguages, error) Close() @@ -82,7 +82,7 @@ var ( indexerQueue queue.UniqueQueue ) -func index(indexer Indexer, repoID int64) error { +func index(ctx context.Context, indexer Indexer, repoID int64) error { repo, err := repo_model.GetRepositoryByID(repoID) if repo_model.IsErrRepoNotExist(err) { return indexer.Delete(repoID) @@ -91,18 +91,18 @@ func index(indexer Indexer, repoID int64) error { return err } - sha, err := getDefaultBranchSha(repo) + sha, err := getDefaultBranchSha(ctx, repo) if err != nil { return err } - changes, err := getRepoChanges(repo, sha) + changes, err := getRepoChanges(ctx, repo, sha) if err != nil { return err } else if changes == nil { return nil } - if err := indexer.Index(repo, sha, changes); err != nil { + if err := indexer.Index(ctx, repo, sha, changes); err != nil { return err } @@ -150,7 +150,7 @@ func Init() { } log.Trace("IndexerData Process Repo: %d", indexerData.RepoID) - if err := index(indexer, indexerData.RepoID); err != nil { + if err := index(ctx, indexer, indexerData.RepoID); err != nil { log.Error("index: %v", err) continue } |