You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
forgejo/modules
Peter Gardfjäll e28cc79c92
Improve sync performance for pull-mirrors (#19125)
This addresses https://github.com/go-gitea/gitea/issues/18352

It aims to improve performance (and resource use) of the `SyncReleasesWithTags` operation for pull-mirrors.

For large repositories with many tags, `SyncReleasesWithTags` can be a costly operation (taking several minutes to complete). The reason is two-fold:
    
1. on sync, every upstream repo tag is compared (for changes) against existing local entries in the release table to ensure that they are up-to-date.
    
2. the procedure for getting _each tag_ involves a series of git operations    
    ```bash
     git show-ref --tags -- v8.2.4477
     git cat-file -t 29ab6ce9f36660cffaad3c8789e71162e5db5d2f
     git cat-file -p 29ab6ce9f36660cffaad3c8789e71162e5db5d2f
     git rev-list --count 29ab6ce9f36660cffaad3c8789e71162e5db5d2f
     ```    

     of which the `git rev-list --count` can be particularly heavy.
    
This PR optimizes performance for pull-mirrors. We utilize the fact that a pull-mirror is always identical to its upstream and rebuild the entire release table on every sync and use a batch `git for-each-ref .. refs/tags` call to retrieve all tags in one go.
    
For large mirror repos, with hundreds of annotated tags, this brings down the duration of the sync operation from several minutes to a few seconds. A few unscientific examples run on my local machine:

- https://github.com/spring-projects/spring-boot (223 tags)
  - before: `0m28,673s`
  - after: `0m2,244s`
- https://github.com/kubernetes/kubernetes (890 tags)
  - before: `8m00s`
  - after: `0m8,520s`
- https://github.com/vim/vim (13954 tags)
  - before: `14m20,383s`
  - after: `0m35,467s`

 

I added a `foreachref` package which contains a flexible way of specifying which reference fields are of interest (`git-for-each-ref(1)`) and to produce a parser for the expected output. These could be reused in other places where `for-each-ref` is used.  I'll add unit tests for those if the overall PR looks promising.
2 years ago
..
activitypub format with gofumpt (#18184) 2 years ago
analyze Use git attributes to determine generated and vendored status for language stats and diffs (#16773) 3 years ago
appstate format with gofumpt (#18184) 2 years ago
auth RSS/Atom support for Repos (#19055) 2 years ago
avatar format with gofumpt (#18184) 2 years ago
base format with gofumpt (#18184) 2 years ago
cache format with gofumpt (#18184) 2 years ago
charset Don't treat BOM escape sequence as hidden character. (#18909) 2 years ago
container Move reaction to models/issues/ (#19264) 2 years ago
context Add Package Registry (#16510) 2 years ago
convert Add Package Registry (#16510) 2 years ago
csv format with gofumpt (#18184) 2 years ago
doctor Make git.OpenRepository accept Context (#19260) 2 years ago
emoji format with gofumpt (#18184) 2 years ago
eventsource Simplify parameter types (#18006) 3 years ago
generate Use base32 for 2FA scratch token (#18384) 2 years ago
git Improve sync performance for pull-mirrors (#19125) 2 years ago
gitgraph Make git.OpenRepository accept Context (#19260) 2 years ago
graceful Add pprof labels in processes and for lifecycles (#19202) 2 years ago
hcaptcha hCaptcha Support (#12594) 4 years ago
highlight format with gofumpt (#18184) 2 years ago
hostmatcher remove not needed (#19128) 2 years ago
httpcache format with gofumpt (#18184) 2 years ago
httplib refactor httplib (#18338) 2 years ago
indexer Make git.OpenRepository accept Context (#19260) 2 years ago
json Make gitea, gitea-vet future-proof (#18361) 2 years ago
lfs Update HTTP status codes to modern codes (#18063) 2 years ago
log Add auto logging of goroutine pid label (#19212) 2 years ago
markup Make git.OpenRepository accept Context (#19260) 2 years ago
metrics format with gofumpt (#18184) 2 years ago
migration Store the foreign ID of issues during migration (#18446) 2 years ago
nosql Add Redis Sentinel Authentication Support (#19213) 2 years ago
notification Add Package Registry (#16510) 2 years ago
options format with gofumpt (#18184) 2 years ago
packages Add Package Registry (#16510) 2 years ago
password Fixed assert statements. (#16089) 3 years ago
pprof refactor: move from io/ioutil to io and os package (#17109) 3 years ago
private Update HTTP status codes to modern codes (#18063) 2 years ago
process Refactor `git.Command.Run*`, introduce `RunWithContextString` and `RunWithContextBytes` (#19266) 2 years ago
proxy Return nil proxy function if proxy not enabled (#16742) 3 years ago
public Fix mime-type detection for HTTP server (#18370) 2 years ago
queue Add number in queue status to monitor page (#18712) 2 years ago
recaptcha refactor: move from io/ioutil to io and os package (#17109) 3 years ago
references format with gofumpt (#18184) 2 years ago
repository Improve sync performance for pull-mirrors (#19125) 2 years ago
secret Use `CryptoRandomBytes` instead of `CryptoRandomString` (#18439) 2 years ago
session format with gofumpt (#18184) 2 years ago
setting Add Package Registry (#16510) 2 years ago
ssh Update golang.org/x/crypto (#19097) 2 years ago
storage Add Package Registry (#16510) 2 years ago
structs Add Package Registry (#16510) 2 years ago
svg refactor: move from io/ioutil to io and os package (#17109) 3 years ago
sync Fix missing unlock in uniquequeue (#9790) 5 years ago
templates Add Package Registry (#16510) 2 years ago
test Make git.OpenRepository accept Context (#19260) 2 years ago
timeutil format with gofumpt (#18184) 2 years ago
translation Refactor i18n, use Locale to provide i18n/translation related functions (#18648) 2 years ago
typesniffer format with gofumpt (#18184) 2 years ago
updatechecker format with gofumpt (#18184) 2 years ago
upload Simplify parameter types (#18006) 3 years ago
uri Prevent NPE if gitea uploader fails to open url (#18080) 3 years ago
user Add gitea-vet (#10948) 4 years ago
util Use a more general (and faster) method to sanitize URLs with credentials (#19239) 2 years ago
validation format with gofumpt (#18184) 2 years ago
web Update HTTP status codes to modern codes (#18063) 2 years ago