[fix] Enqueue syncing global search (#3455)
* [fix] Enqueue syncing global search * make passing flags optional * Create global_search.py
This commit is contained in:
parent
00786178e5
commit
d8fb2c2c0d
3 changed files with 19 additions and 10 deletions
|
|
@ -14,6 +14,7 @@ import frappe
|
|||
import frappe.defaults
|
||||
import frappe.async
|
||||
import re
|
||||
import redis
|
||||
import frappe.model.meta
|
||||
from frappe.utils import now, get_datetime, cstr
|
||||
from frappe import _
|
||||
|
|
@ -723,8 +724,16 @@ class Database:
|
|||
self.sql("commit")
|
||||
frappe.local.rollback_observers = []
|
||||
self.flush_realtime_log()
|
||||
|
||||
if frappe.flags.update_global_search:
|
||||
sync_global_search()
|
||||
try:
|
||||
frappe.enqueue('frappe.utils.global_search.sync_global_search',
|
||||
now=frappe.flags.in_test or frappe.flags.in_install or frappe.flags.in_migrate,
|
||||
flags=frappe.flags.update_global_search)
|
||||
except redis.exceptions.ConnectionError:
|
||||
sync_global_search()
|
||||
|
||||
frappe.flags.update_global_search = []
|
||||
|
||||
def flush_realtime_log(self):
|
||||
for args in frappe.local.realtime_log:
|
||||
|
|
|
|||
|
|
@ -803,12 +803,7 @@ class Document(BaseDocument):
|
|||
self.clear_cache()
|
||||
self.notify_update()
|
||||
|
||||
try:
|
||||
frappe.enqueue('frappe.utils.global_search.update_global_search',
|
||||
now=frappe.flags.in_test or frappe.flags.in_install or frappe.flags.in_migrate,
|
||||
doc=self)
|
||||
except redis.exceptions.ConnectionError:
|
||||
update_global_search(self)
|
||||
update_global_search(self)
|
||||
|
||||
if self._doc_before_save and not self.flags.ignore_version:
|
||||
self.save_version()
|
||||
|
|
|
|||
|
|
@ -244,11 +244,16 @@ def get_formatted_value(value, field):
|
|||
value = ' '.join(value.split())
|
||||
return field.label + " : " + strip_html_tags(unicode(value))
|
||||
|
||||
def sync_global_search():
|
||||
'''Add values from `frappe.flags.update_global_search` to __global_search.
|
||||
def sync_global_search(flags=None):
|
||||
'''Add values from `flags` (frappe.flags.update_global_search) to __global_search.
|
||||
This is called internally at the end of the request.'''
|
||||
|
||||
for value in frappe.flags.update_global_search:
|
||||
if not flags:
|
||||
flags = frappe.flags.update_global_search
|
||||
|
||||
# Can pass flags manually as frappe.flags.update_global_search isn't reliable at a later time,
|
||||
# when syncing is enqueued
|
||||
for value in flags:
|
||||
frappe.db.sql('''
|
||||
insert into __global_search
|
||||
(doctype, name, content, published, title, route)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue