Commit aaf4a10e authored by Jérome Perrin's avatar Jérome Perrin

web_renderjs: optimize post upgrade constraints

by using getDocumentValueList to lookup all documents at once instead
of using getDocumentValue for each document
parent 517a8aed
from DateTime import DateTime from DateTime import DateTime
appcache_reference = context.getLayoutProperty("configuration_manifest_url") appcache_reference = context.getLayoutProperty("configuration_manifest_url")
getDocumentValue = context.getDocumentValue
error_list = [] error_list = []
if appcache_reference: if appcache_reference:
appcache_manifest = getDocumentValue(appcache_reference) appcache_manifest = context.getDocumentValue(appcache_reference)
if not appcache_manifest: if not appcache_manifest:
return ['Error: Web Site %s references a non existant appcache %s' % (context.getRelativeUrl(),appcache_reference)] return ['Error: Web Site %s references a non existant appcache %s' % (context.getRelativeUrl(),appcache_reference)]
url_list = context.Base_getListFileFromAppcache() url_list = [url for url in context.Base_getListFileFromAppcache() if url]
# Check that the manifest is newer than all cached resources. # Check that the manifest is newer than all cached resources.
appcache_manifest_modification_date = appcache_manifest.getObject().getModificationDate() appcache_manifest_modification_date = appcache_manifest.getObject().getModificationDate()
for url in url_list:
if url: if url_list:
referenced_document = getDocumentValue(url) for referenced_document in context.getDocumentValueList(reference=url_list):
if referenced_document is not None and ( if referenced_document.getModificationDate() > appcache_manifest_modification_date:
referenced_document.getModificationDate() >
appcache_manifest_modification_date):
error_list.append( error_list.append(
"Document {} is newer than cache manifest".format(url)) "Document {} is newer than cache manifest".format(referenced_document.getReference()))
if error_list and fixit: if error_list and fixit:
text_list = appcache_manifest.getTextContent().split('\n') text_list = appcache_manifest.getTextContent().split('\n')
......
...@@ -13,12 +13,18 @@ Base_translateString = context.Base_translateString ...@@ -13,12 +13,18 @@ Base_translateString = context.Base_translateString
translatable_message_set = set([]) translatable_message_set = set([])
web_page_reference_list = context.Base_getTranslationSourceFileList(only_html=1) web_page_reference_list = context.Base_getTranslationSourceFileList(only_html=1)
web_page_by_reference = {}
if web_page_reference_list:
web_page_list = [
b.getObject() for b in
context.getDocumentValueList(reference=web_page_reference_list)]
web_page_by_reference = {wp.getReference(): wp.getTextContent() for wp in web_page_list}
for web_page_reference in web_page_reference_list: for web_page_reference in web_page_reference_list:
# Web pages can be in web page module ... # Web pages can be in web page module ...
web_page = context.getDocumentValue(web_page_reference) web_page_text_content = web_page_by_reference.get(web_page_reference)
if web_page is not None: if web_page_text_content is None:
web_page_text_content = web_page.getTextContent()
else:
# ... or in skin folders # ... or in skin folders
web_page = context.restrictedTraverse(web_page_reference, None) web_page = context.restrictedTraverse(web_page_reference, None)
if web_page is not None and hasattr(web_page, 'PrincipiaSearchSource'): if web_page is not None and hasattr(web_page, 'PrincipiaSearchSource'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment