Skip to content

Commit

Permalink
perf(HelpdeskSearch): Don't read all tickets for count
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurali27 committed Sep 10, 2024
1 parent 4f6c2e4 commit 4c62192
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions helpdesk/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,14 @@ def drop_index(self):
with suppress(ResponseError): # Index may not exist
self.redis.ft(self.index_name).dropindex(delete_documents=True)

def get_records(self, doctype: str): # noqa
def get_count(self, doctype):
raise NotImplementedError

def get_all_records(self):
def num_records(self) -> int:
num = 0
for doctype in self.DOCTYPE_FIELDS.keys():
yield from self.get_records(doctype)

def num_records(self):
return len(list(self.get_all_records()))
num += self.get_count(doctype)
return num

def index_exists(self):
if hasattr(self, "_index_exists"):
Expand Down Expand Up @@ -285,6 +284,12 @@ def scrub(self, text: str):
# For permalink
return re.sub(r"[^a-zA-Z0-9]+", "-", text).lower()

def get_count(self, doctype):
if doctype == "HD Ticket":
return frappe.db.count(doctype)
if doctype == "HD Article":
return len(self.get_records(doctype))

def get_records(self, doctype):
records = []
for d in frappe.db.get_all(doctype, fields=self.DOCTYPE_FIELDS[doctype]):
Expand Down

0 comments on commit 4c62192

Please sign in to comment.