summaryrefslogtreecommitdiffstats
path: root/vendor/xorm.io/xorm/session_iterate.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-03-22 23:12:55 +0800
committerGitHub <noreply@github.com>2020-03-22 11:12:55 -0400
commitc61b902538e8e4b2bb83136f190e044a6bbcdd9b (patch)
treebc08142f5ced69721ab14793b8dc62aa83314268 /vendor/xorm.io/xorm/session_iterate.go
parentdcaa5643d70cd1be72e53e82a30d2bc6e5f8de92 (diff)
downloadgitea-c61b902538e8e4b2bb83136f190e044a6bbcdd9b.tar.gz
gitea-c61b902538e8e4b2bb83136f190e044a6bbcdd9b.zip
Upgrade xorm to v1.0.0 (#10646)
* Upgrade xorm to v1.0.0 * small nit * Fix tests * Update xorm * Update xorm * fix go.sum * fix test * Fix bug when dump * Fix bug * update xorm to latest * Fix migration test * update xorm to latest * Fix import order * Use xorm tag
Diffstat (limited to 'vendor/xorm.io/xorm/session_iterate.go')
-rw-r--r--vendor/xorm.io/xorm/session_iterate.go47
1 files changed, 26 insertions, 21 deletions
diff --git a/vendor/xorm.io/xorm/session_iterate.go b/vendor/xorm.io/xorm/session_iterate.go
index ca996c2884..8cab8f48f4 100644
--- a/vendor/xorm.io/xorm/session_iterate.go
+++ b/vendor/xorm.io/xorm/session_iterate.go
@@ -4,7 +4,11 @@
package xorm
-import "reflect"
+import (
+ "reflect"
+
+ "xorm.io/xorm/internal/utils"
+)
// IterFunc only use by Iterate
type IterFunc func(idx int, bean interface{}) error
@@ -23,11 +27,11 @@ func (session *Session) Iterate(bean interface{}, fun IterFunc) error {
defer session.Close()
}
- if session.statement.lastError != nil {
- return session.statement.lastError
+ if session.statement.LastError != nil {
+ return session.statement.LastError
}
- if session.statement.bufferSize > 0 {
+ if session.statement.BufferSize > 0 {
return session.bufferIterate(bean, fun)
}
@@ -55,27 +59,28 @@ func (session *Session) Iterate(bean interface{}, fun IterFunc) error {
// BufferSize sets the buffersize for iterate
func (session *Session) BufferSize(size int) *Session {
- session.statement.bufferSize = size
+ session.statement.BufferSize = size
return session
}
func (session *Session) bufferIterate(bean interface{}, fun IterFunc) error {
- if session.isAutoClose {
- defer session.Close()
- }
-
- var bufferSize = session.statement.bufferSize
- var limit = session.statement.LimitN
- if limit > 0 && bufferSize > limit {
- bufferSize = limit
+ var bufferSize = session.statement.BufferSize
+ var pLimitN = session.statement.LimitN
+ if pLimitN != nil && bufferSize > *pLimitN {
+ bufferSize = *pLimitN
}
var start = session.statement.Start
- v := rValue(bean)
+ v := utils.ReflectValue(bean)
sliceType := reflect.SliceOf(v.Type())
var idx = 0
- for {
+ session.autoResetStatement = false
+ defer func() {
+ session.autoResetStatement = true
+ }()
+
+ for bufferSize > 0 {
slice := reflect.New(sliceType)
- if err := session.Limit(bufferSize, start).find(slice.Interface(), bean); err != nil {
+ if err := session.NoCache().Limit(bufferSize, start).find(slice.Interface(), bean); err != nil {
return err
}
@@ -86,13 +91,13 @@ func (session *Session) bufferIterate(bean interface{}, fun IterFunc) error {
idx++
}
- start = start + slice.Elem().Len()
- if limit > 0 && idx+bufferSize > limit {
- bufferSize = limit - idx
+ if bufferSize > slice.Elem().Len() {
+ break
}
- if bufferSize <= 0 || slice.Elem().Len() < bufferSize || idx == limit {
- break
+ start = start + slice.Elem().Len()
+ if pLimitN != nil && start+bufferSize > *pLimitN {
+ bufferSize = *pLimitN - start
}
}