fetchNextBatch fetches the next batch of references from the database.
()
| 135 | |
| 136 | // fetchNextBatch fetches the next batch of references from the database. |
| 137 | func (iter *ReferenceIter) fetchNextBatch() error { |
| 138 | var results []database.Reference |
| 139 | result := iter.db.Where("url = ?", iter.namespacePrefix).Offset(iter.offset).Limit(iter.limit).Find(&results) |
| 140 | if result.Error != nil { |
| 141 | iter.moreData = false |
| 142 | return result.Error |
| 143 | } |
| 144 | iter.offset += len(results) |
| 145 | iter.moreData = len(results) == iter.limit |
| 146 | |
| 147 | // Convert database references to plumbing.Reference |
| 148 | iter.refs = make([]*plumbing.Reference, len(results)) |
| 149 | for i, dbRef := range results { |
| 150 | var ref *plumbing.Reference |
| 151 | switch dbRef.Type { |
| 152 | case plumbing.HashReference.String(): |
| 153 | ref = plumbing.NewHashReference(plumbing.ReferenceName(dbRef.Name), plumbing.NewHash(dbRef.Target)) |
| 154 | case plumbing.SymbolicReference.String(): |
| 155 | ref = plumbing.NewSymbolicReference(plumbing.ReferenceName(dbRef.Name), plumbing.ReferenceName(dbRef.Target)) |
| 156 | default: |
| 157 | return errors.New("unknown reference type") |
| 158 | } |
| 159 | iter.refs[i] = ref |
| 160 | } |
| 161 | return nil |
| 162 | } |
| 163 | |
| 164 | // Next retrieves the next reference, advancing the iterator. |
| 165 | func (iter *ReferenceIter) Next() (*plumbing.Reference, error) { |