0
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-02-19 01:00:19 +01:00

[gitea] fix: Elasticsearch: Request Entity Too Large ()

Fix for gitea putting everything into one request without batching and
sending it to Elasticsearch for indexing as issued in 

This issue occured in large repositories while Gitea tries to
index the code using ElasticSearch.

I've applied necessary changes that takes batch length from below config
(app.ini)
```
[queue.code_indexer]
BATCH_LENGTH=<length_int>
```
and batches all requests to Elasticsearch in chunks as configured in the
above config

(cherry picked from commit 5c0fc9087211f01375f208d679a1e6de0685320c)
This commit is contained in:
dark-angel 2024-02-07 14:27:16 +05:30 committed by Earl Warren
parent 75937b5784
commit 00370f17a4
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -180,11 +180,17 @@ func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha st
}
if len(reqs) > 0 {
_, err := b.inner.Client.Bulk().
Index(b.inner.VersionedIndexName()).
Add(reqs...).
Do(ctx)
return err
esBatchSize := 50
for i := 0; i < len(reqs); i += esBatchSize {
_, err := b.inner.Client.Bulk().
Index(b.inner.VersionedIndexName()).
Add(reqs[i:min(i+esBatchSize, len(reqs))]...).
Do(ctx)
if err != nil {
return err
}
}
}
return nil
}