Skip to content

Commit

Permalink
Fix new id bug
Browse files Browse the repository at this point in the history
  • Loading branch information
makseq committed Dec 15, 2020
1 parent e34e4cd commit 5926b0f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions label_studio/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ def _extract_task_id(self, full_key):
"""Infer task ID from specified key (e.g. by splitting tasks.json/123)"""
pass

def _get_new_id(self, key, new_id):
idx = self._extract_task_id(key)
if idx is not None:
return idx, new_id
idx = new_id
new_id += 1
return idx, new_id

def _sync(self):
with self.thread_lock:
self.last_sync_time = datetime.now()
Expand All @@ -426,18 +434,9 @@ def _sync(self):
intersect = full & OrderedSet(self._keys_ids_map)
exclusion = full - intersect

def _get_new_id(key):
global new_id
id = self._extract_task_id(key)
if id is not None:
return id
id = new_id
new_id += 1
return id

# new tasks
for key in exclusion:
id = _get_new_id(key)
id, new_id = self._get_new_id(key, new_id)
new_ids_keys_map[id] = {'key': key, 'exists': True}
new_keys_ids_map[key] = id

Expand Down

0 comments on commit 5926b0f

Please sign in to comment.