Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/in_memory.py
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | def add(self, data, conflict_update): | ||||
- **indexer_configuration_id**: tool used to compute the | - **indexer_configuration_id**: tool used to compute the | ||||
results | results | ||||
- arbitrary data | - arbitrary data | ||||
conflict_update (bool): Flag to determine if we want to overwrite | conflict_update (bool): Flag to determine if we want to overwrite | ||||
(true) or skip duplicates (false) | (true) or skip duplicates (false) | ||||
""" | """ | ||||
data = list(data) | |||||
if len({x['id'] for x in data}) < len(data): | |||||
# For "exception-compatibility" with the pgsql backend | |||||
raise ValueError('The same id is present more than once.') | |||||
for item in data: | for item in data: | ||||
item = item.copy() | item = item.copy() | ||||
tool_id = item.pop('indexer_configuration_id') | tool_id = item.pop('indexer_configuration_id') | ||||
id_ = item.pop('id') | id_ = item.pop('id') | ||||
data = item | data = item | ||||
if not conflict_update and \ | if not conflict_update and \ | ||||
tool_id in self._tools_per_id.get(id_, set()): | tool_id in self._tools_per_id.get(id_, set()): | ||||
# Duplicate, should not be updated | # Duplicate, should not be updated | ||||
▲ Show 20 Lines • Show All 603 Lines • Show Last 20 Lines |