704
704
records = [(c, p, s) for c, (m, p, s, n) in position_map.iteritems()]
706
706
for component_id, content, digest in \
707
self._data.read_records_iter_unsorted(records):
707
self._data.read_records_iter(records):
708
708
method, position, size, next = position_map[component_id]
709
709
record_map[component_id] = method, content, digest, next
807
807
pb.update('Walking content.', count, total)
808
808
for version_id, data, sha_value in \
809
self._data.read_records_iter_unsorted(version_id_records):
809
self._data.read_records_iter(version_id_records):
810
810
pb.update('Walking content.', count, total)
811
811
method = self._index.get_method(version_id)
812
812
version_idx = self._index.lookup(version_id)
1424
1424
def read_records_iter(self, records):
1425
1425
"""Read text records from data file and yield result.
1427
Each passed record is a tuple of (version_id, pos, len) and
1428
will be read in the given order. Yields (version_id,
1431
n_records = len(records)
1435
record_requests = {}
1436
for record in records:
1437
y = record_requests.setdefault(record, 0)
1440
# Keep track of where we are in the record list
1441
# Alternatively we could turn this into a new list
1442
# reverse it, and pop off the end, that would let
1443
# us assert that we had gotten through the whole thing
1444
record_stack = iter(records)
1445
next_record = record_stack.next()
1449
for version_id, content, digest in \
1450
self.read_records_iter_unsorted(records):
1451
record_map[version_id] = (content, digest)
1453
while next_record[0] in record_map:
1454
next_content, next_digest = record_map[next_record[0]]
1455
record_requests[next_record] -= 1
1456
if record_requests[next_record] == 0:
1457
del record_map.pop[next_record]
1459
yield next_record[0], next_content, next_digest
1460
next_record = record_stack.next()
1462
# When we get this far, the record_stack should be empty
1463
assert yield_count == n_records
1464
assert record_map == {}, 'We still have records queued up'
1466
def read_records_iter_unsorted(self, records):
1467
"""Read text records from data file and yield result.
1469
1427
The result will be returned in whatever is the fastest to read.
1470
1428
Not by the order requested. Also, multiple requests for the same
1471
1429
record will only yield 1 response.
1513
1471
"""Read records into a dictionary."""
1514
1472
components = {}
1515
1473
for record_id, content, digest in \
1516
self.read_records_iter_unsorted(records):
1474
self.read_records_iter(records):
1517
1475
components[record_id] = (content, digest)
1518
1476
return components