f"'{self.storage_path}' is not a valid directory."\r
)\r
self.index = self._load_index()\r
- self._sync_index()\r
+ self._sync_index(optimize=True)\r
\r
def create(self, data: NoteCreate) -> Note:\r
"""Create a new note."""\r
return tuple(self._search_result_from_hit(hit) for hit in results)\r
\r
def get_tags(self) -> list[str]:\r
- """Return a list of all indexed tags."""\r
- self._sync_index()\r
+ """Return a list of all indexed tags. The index is synchronized and\r
+ optimised before returning the tags to ensure the most up-to-date list\r
+ is returned."""\r
+ self._sync_index(optimize=True)\r
with self.index.reader() as reader:\r
tags = reader.field_terms("tags")\r
return [tag for tag in tags]\r
)\r
]\r
\r
- def _sync_index(self, clean: bool = False) -> None:\r
+ def _sync_index(self, optimize: bool = False, clean: bool = False) -> None:\r
"""Synchronize the index with the notes directory.\r
Specify clean=True to completely rebuild the index"""\r
indexed = set()\r
writer, self._get_by_filename(filename)\r
)\r
logger.info(f"'{filename}' added to index")\r
- writer.commit()\r
+ writer.commit(optimize=optimize)\r
\r
@classmethod\r
def _pre_process_search_term(cls, term):\r