Skip to content
Snippets Groups Projects
Verified Commit 42346f8b authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

indexers: Fix summary computation for range indexers

parent 91ec22ca
No related branches found
Tags v0.0.166
No related merge requests found
......@@ -471,6 +471,7 @@ class ContentRangeIndexer(BaseIndexer):
"""
status = 'uneventful'
summary: Dict[str, Any] = {}
count = 0
try:
range_start = hashutil.hash_to_bytes(start) \
if isinstance(start, str) else start
......@@ -484,16 +485,17 @@ class ContentRangeIndexer(BaseIndexer):
gen = self._index_contents(
range_start, range_end, indexed=set([]))
key: Optional[str] = None
count_object_added_key: Optional[str] = None
for contents in utils.grouper(
gen, n=self.config['write_batch_size']):
res = self.persist_index_computations(
contents, policy_update='update-dups')
if not key:
key = list(res.keys())[0]
summary[key] += res[key]
status = 'eventful'
if not count_object_added_key:
count_object_added_key = list(res.keys())[0]
count += res[count_object_added_key]
if count > 0:
status = 'eventful'
except Exception:
if not self.catch_exceptions:
raise
......@@ -502,6 +504,8 @@ class ContentRangeIndexer(BaseIndexer):
status = 'failed'
finally:
summary['status'] = status
if count > 0 and count_object_added_key:
summary[count_object_added_key] = count
return summary
......
# Copyright (C) 2017-2019 The Software Heritage developers
# Copyright (C) 2017-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
......@@ -734,7 +734,7 @@ class CommonContentIndexerRangeTest:
actual_results = self.indexer.run(start, end)
# then
self.assertTrue(actual_results)
self.assertEqual(actual_results, {'status': 'uneventful'})
def test_generate_content_get_input_as_bytes(self):
"""Optimal indexing should result in indexed data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment