refactor: Use global redis connection

This commit is contained in:
Hussain Nagaria
2021-04-29 20:47:32 +05:30
parent 58d08ee307
commit a6deace37c
2 changed files with 32 additions and 20 deletions

View File

@@ -12,7 +12,8 @@ from redisearch import AutoCompleter, Client, Query
from erpnext.e_commerce.website_item_indexing import (
WEBSITE_ITEM_INDEX,
WEBSITE_ITEM_NAME_AUTOCOMPLETE,
WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE
WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE,
make_key
)
# -----------------
@@ -64,8 +65,10 @@ def search(query):
# TODO: return top/recent searches
return []
ac = AutoCompleter(WEBSITE_ITEM_NAME_AUTOCOMPLETE, port=13000)
client = Client(WEBSITE_ITEM_INDEX, port=13000)
red = frappe.cache()
ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=red)
client = Client(make_key(WEBSITE_ITEM_INDEX), conn=red)
suggestions = ac.get_suggestions(query, num=10)
# Build a query
@@ -94,7 +97,7 @@ def get_category_suggestions(query):
# TODO: return top/recent searches
return []
ac = AutoCompleter(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE, port=13000)
ac = AutoCompleter(make_key(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE), conn=frappe.cache())
suggestions = ac.get_suggestions(query, num=10)
return [s.string for s in suggestions]