From 0823f6bc767af3630e8f8ef14b941588c9e5c988 Mon Sep 17 00:00:00 2001 From: Alaeddine Abdessalem Date: Thu, 3 Feb 2022 16:20:31 +0100 Subject: [PATCH 1/2] perf: implement append to avoid invalidating id2offset --- docarray/array/storage/memory/seqlike.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docarray/array/storage/memory/seqlike.py b/docarray/array/storage/memory/seqlike.py index 633d7c1fd66..8222ca7dfa7 100644 --- a/docarray/array/storage/memory/seqlike.py +++ b/docarray/array/storage/memory/seqlike.py @@ -17,6 +17,15 @@ def insert(self, index: int, value: 'Document'): """ self._data.insert(index, value) + def append(self, value: 'Document'): + """Append `doc` to the end of the array. + + :param value: The doc needs to be appended. + """ + self._data.append(value) + if not self._needs_id2offset_rebuild: + self._id_to_index[value.id] = len(self) + def __eq__(self, other): return ( type(self) is type(other) From 3a15c8cbf3545d7431b9943ab6f6422bb61076e6 Mon Sep 17 00:00:00 2001 From: Alaeddine Abdessalem Date: Thu, 3 Feb 2022 16:39:17 +0100 Subject: [PATCH 2/2] fix: add the correct offset --- docarray/array/storage/memory/seqlike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docarray/array/storage/memory/seqlike.py b/docarray/array/storage/memory/seqlike.py index 8222ca7dfa7..a607d1c9f50 100644 --- a/docarray/array/storage/memory/seqlike.py +++ b/docarray/array/storage/memory/seqlike.py @@ -24,7 +24,7 @@ def append(self, value: 'Document'): """ self._data.append(value) if not self._needs_id2offset_rebuild: - self._id_to_index[value.id] = len(self) + self._id_to_index[value.id] = len(self) - 1 def __eq__(self, other): return (