fix: break first
This commit is contained in:
		
							parent
							
								
									cd35587764
								
							
						
					
					
						commit
						8b19b51425
					
				@ -212,13 +212,12 @@ func (db *DB) FindInBatches(dest interface{}, batchSize int, fc func(tx *DB, bat
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if totalSize > 0 {
 | 
							if totalSize > 0 {
 | 
				
			||||||
			if totalSize/batchSize == batch {
 | 
					 | 
				
			||||||
				batchSize = totalSize % batchSize
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if totalSize <= int(rowsAffected) {
 | 
								if totalSize <= int(rowsAffected) {
 | 
				
			||||||
				break
 | 
									break
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								if totalSize/batchSize == batch {
 | 
				
			||||||
 | 
									batchSize = totalSize % batchSize
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Optimize for-break
 | 
							// Optimize for-break
 | 
				
			||||||
 | 
				
			|||||||
@ -336,6 +336,12 @@ func TestFindInBatchesWithOffsetLimit(t *testing.T) {
 | 
				
			|||||||
	}); result.Error != nil || result.RowsAffected != 5 {
 | 
						}); result.Error != nil || result.RowsAffected != 5 {
 | 
				
			||||||
		t.Errorf("Failed to batch find, got error %v, rows affected: %v", result.Error, result.RowsAffected)
 | 
							t.Errorf("Failed to batch find, got error %v, rows affected: %v", result.Error, result.RowsAffected)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if result := DB.Limit(4).Where("name = ?", users[0].Name).FindInBatches(&sub, 2, func(tx *gorm.DB, batch int) error {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}); result.Error != nil || result.RowsAffected != 4 {
 | 
				
			||||||
 | 
							t.Errorf("Failed to batch find, got error %v, rows affected: %v", result.Error, result.RowsAffected)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestFindInBatchesWithError(t *testing.T) {
 | 
					func TestFindInBatchesWithError(t *testing.T) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user