Skip to content

Commit

Permalink
chore: optimze code
Browse files Browse the repository at this point in the history
  • Loading branch information
cir9no committed Jan 2, 2025
1 parent 2e87d37 commit 1c7a4c8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions seasearch/index_store/wiki_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,14 @@ def get_wiki_conf(self, wiki_id, commit_id=None):
f = fs_mgr.load_seafile(wiki_id, 1, file_id)
return json.loads(f.get_content().decode())

def get_updated_title_uuids(self, old_conf, new_conf):
def get_updated_title_uuids(self, old_conf, new_conf, excluded_uuids=None):
"""Calculate the items that are in new_conf but not in old_conf,
or the names in New_conf are different from the names in old_conf.
return based on new_conf data
Args:
old_conf: get from get_wiki_conf
new_conf: get from get_wiki_conf
excluded_uuids: set of doc_uuids that should be excluded from the result
Returns:
set: A set of doc_uuids for updated titles."""

Expand All @@ -167,6 +168,8 @@ def get_updated_title_uuids(self, old_conf, new_conf):
if new_id not in old_pages or new_page['name'] != old_pages[new_id]['name']:
doc_uuids.add(new_page['docUuid'])

if excluded_uuids:
doc_uuids.difference_update(excluded_uuids)
return doc_uuids

def get_uuid_path_mapping(self, config):
Expand Down Expand Up @@ -308,9 +311,9 @@ def update(self, index_name, wiki_id, old_commit_id, new_commit_id):
is_wiki_conf_modified = any(wiki_conf_path == tup[0].lstrip('/') for tup in need_added_files)

if is_wiki_conf_modified:
updated_title_uuids = self.get_updated_title_uuids(old_cfg, new_cfg)
#Remove the uuids that are in the recycle bin
need_updated_title_uuids = updated_title_uuids.difference_update(curr_recycled_uuid_paths.keys())
need_updated_title_uuids = self.wiki_index.get_updated_title_uuids(
old_cfg, new_cfg, excluded_uuids=curr_recycled_uuid_paths.keys()
)
else:
need_updated_title_uuids = set()

Expand Down

0 comments on commit 1c7a4c8

Please sign in to comment.