mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 18:59:08 +00:00
fixes in web cache record insert for exceptional pages like 404, login-page, index etc.
This commit is contained in:
@@ -33,27 +33,5 @@ def cleanup():
|
|||||||
|
|
||||||
def save_pages():
|
def save_pages():
|
||||||
"""save all web pages, blogs to create content"""
|
"""save all web pages, blogs to create content"""
|
||||||
import webnotes
|
import website.web_cache
|
||||||
from webnotes.model.doclist import DocList
|
website.web_cache.rebuild_web_cache()
|
||||||
save_list = [
|
|
||||||
{
|
|
||||||
'doctype': 'Web Page',
|
|
||||||
'query': """select name from `tabWeb Page` where docstatus=0"""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'doctype': 'Blog',
|
|
||||||
'query': """\
|
|
||||||
select name from `tabBlog`
|
|
||||||
where docstatus = 0 and ifnull(published, 0) = 1"""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'doctype': 'Item',
|
|
||||||
'query': """\
|
|
||||||
select name from `tabItem`
|
|
||||||
where docstatus = 0 and ifnull(show_in_website, 'No') = 'Yes'"""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
for s in save_list:
|
|
||||||
for p in webnotes.conn.sql(s['query'], as_dict=1):
|
|
||||||
DocList(s['doctype'], p['name']).save()
|
|
||||||
@@ -14,6 +14,8 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
page_exception_list = ['404', 'blog', 'products', 'login-page']
|
||||||
|
|
||||||
# used by web.py
|
# used by web.py
|
||||||
def load_from_web_cache(page_name, comments, template):
|
def load_from_web_cache(page_name, comments, template):
|
||||||
"""
|
"""
|
||||||
@@ -23,17 +25,13 @@ def load_from_web_cache(page_name, comments, template):
|
|||||||
"""
|
"""
|
||||||
import webnotes
|
import webnotes
|
||||||
import conf
|
import conf
|
||||||
|
|
||||||
if page_name == 'index':
|
|
||||||
page_name = get_index_page()[0]
|
|
||||||
|
|
||||||
res = webnotes.conn.sql("""\
|
res = webnotes.conn.sql("""\
|
||||||
select html, doc_type, doc_name from `tabWeb Cache`
|
select html, doc_type, doc_name from `tabWeb Cache`
|
||||||
where name = %s""", page_name)
|
where name = %s""", page_name)
|
||||||
|
|
||||||
# if page doesn't exist, raise exception
|
# if page doesn't exist, raise exception
|
||||||
page_exception_list = ['404', 'index', 'blog', 'products', 'login-page']
|
if not res and page_name not in page_exception_list + ['index']:
|
||||||
if not res and page_name not in page_exception_list:
|
|
||||||
raise Exception, "Page %s not found" % page_name
|
raise Exception, "Page %s not found" % page_name
|
||||||
|
|
||||||
html, doc_type, doc_name = res and res[0] or (None, None, None)
|
html, doc_type, doc_name = res and res[0] or (None, None, None)
|
||||||
@@ -75,7 +73,8 @@ def load_into_web_cache(page_name, template, doc_type, doc_name):
|
|||||||
|
|
||||||
# save html in web cache
|
# save html in web cache
|
||||||
webnotes.conn.begin()
|
webnotes.conn.begin()
|
||||||
clear_web_cache(doc_type, doc_name, page_name)
|
if page_name in page_exception_list + ['index']:
|
||||||
|
clear_web_cache(doc_type, doc_name, page_name)
|
||||||
webnotes.conn.set_value('Web Cache', page_name, 'html', html)
|
webnotes.conn.set_value('Web Cache', page_name, 'html', html)
|
||||||
webnotes.conn.commit()
|
webnotes.conn.commit()
|
||||||
|
|
||||||
@@ -85,7 +84,7 @@ def prepare_args(page_name, doc_type, doc_name, with_outer_env=1):
|
|||||||
if page_name == 'index':
|
if page_name == 'index':
|
||||||
page_name, doc_type, doc_name = get_index_page()
|
page_name, doc_type, doc_name = get_index_page()
|
||||||
|
|
||||||
if page_name in ['404', 'blog', 'products', 'login-page']:
|
if page_name in page_exception_list:
|
||||||
args = {
|
args = {
|
||||||
'name': page_name,
|
'name': page_name,
|
||||||
}
|
}
|
||||||
@@ -143,7 +142,7 @@ def clear_web_cache(doc_type, doc_name, page_name):
|
|||||||
* if a record like (some other type, name) exists, raise exception that the page name is not unique
|
* if a record like (some other type, name) exists, raise exception that the page name is not unique
|
||||||
"""
|
"""
|
||||||
import webnotes
|
import webnotes
|
||||||
res = webnotes.conn.get_value('Web Cache', page_name, 'doc_type')
|
res = webnotes.conn.get_value('Web Cache', page_name, ['doc_type', 'name'])
|
||||||
if not res:
|
if not res:
|
||||||
import webnotes.model.doc
|
import webnotes.model.doc
|
||||||
d = webnotes.model.doc.Document('Web Cache')
|
d = webnotes.model.doc.Document('Web Cache')
|
||||||
@@ -152,11 +151,11 @@ def clear_web_cache(doc_type, doc_name, page_name):
|
|||||||
d.doc_name = doc_name
|
d.doc_name = doc_name
|
||||||
d.html = None
|
d.html = None
|
||||||
d.save()
|
d.save()
|
||||||
elif res == doc_type:
|
elif not doc_type or res[0] == doc_type:
|
||||||
webnotes.conn.set_value('Web Cache', page_name, 'html', None)
|
webnotes.conn.set_value('Web Cache', page_name, 'html', None)
|
||||||
else:
|
else:
|
||||||
webnotes.msgprint("""Page with name "%s" already exists as a %s.
|
webnotes.msgprint("""Page with name "%s" already exists as a %s.
|
||||||
Please save it with another name.""" % (page_name, res), raise_exception=1)
|
Please save it with another name.""" % (page_name, res[0]), raise_exception=1)
|
||||||
|
|
||||||
def clear_all_web_cache():
|
def clear_all_web_cache():
|
||||||
import webnotes
|
import webnotes
|
||||||
@@ -174,6 +173,29 @@ def delete_web_cache(page_name):
|
|||||||
delete from `tabWeb Cache`
|
delete from `tabWeb Cache`
|
||||||
where name=%s""", page_name)
|
where name=%s""", page_name)
|
||||||
|
|
||||||
def build_web_cache():
|
def rebuild_web_cache():
|
||||||
"""build web cache so that pages can load faster"""
|
"""build web cache entries"""
|
||||||
pass
|
import webnotes
|
||||||
|
from webnotes.model.doclist import DocList
|
||||||
|
save_list = [
|
||||||
|
{
|
||||||
|
'doctype': 'Web Page',
|
||||||
|
'query': """select name from `tabWeb Page` where docstatus=0"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'doctype': 'Blog',
|
||||||
|
'query': """\
|
||||||
|
select name from `tabBlog`
|
||||||
|
where docstatus = 0 and ifnull(published, 0) = 1"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'doctype': 'Item',
|
||||||
|
'query': """\
|
||||||
|
select name from `tabItem`
|
||||||
|
where docstatus = 0 and ifnull(show_in_website, 0) = 1"""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for s in save_list:
|
||||||
|
for p in webnotes.conn.sql(s['query'], as_dict=1):
|
||||||
|
DocList(s['doctype'], p['name']).save()
|
||||||
Reference in New Issue
Block a user