GORM Playground Link
It's a reversed test, which means the CI SHOULD FAIL instead of success.
https://github.com/go-gorm/playground/pull/466
Description
The use case is pretty simple. Consider we may have 1k user records, and we want to pre-filter 500 records by like, last login time, then process them in 5 per 100 records batch. The query use FindInBatches will be like:
var singleBatch []User
dbInstance.Limit(500).Offset(100).Where("").FindInBatches(&singleBatch, 100, func(tx *gorm.DB, batch int) error {
// Some operations over singleBatch
})
When using the Limit and Offset clauses, due to the implementation of .FindInBatches, it will cause different issues(Both are covered in the playground):
- Limit: The inner Limit by .FindInBatches will overwrite the originial query, which will fetch all records instead of the desired set.
- Offset: The parameter will be applied in each query, which will skip certain entries over the desired results.
By design, it leads to two solutions:
- If it's the intended behavior, we may should add a warning section in the doc to tell the user not to use it with
limitoroffsetclauses, or even refactor the API to avoid misusing. - If the pre-filtered query should be supported, we may need one or more queries overhead(s) to properly get the query sets since the
whereclause can be pretty complex and it's hard to handle them(e.g., a query will make theidor primary key field not continous).