Commit 66bc7bea authored by Boris Kocherov's avatar Boris Kocherov Committed by Boris Kocherov

erp5_officejs: speedup caching serviceworker

parent b5ca46fa
...@@ -154,8 +154,14 @@ ...@@ -154,8 +154,14 @@
local_sub_storage: { local_sub_storage: {
type: "attachasproperty", type: "attachasproperty",
map: { map: {
text_content: "text_content", text_content: {
data: "data" body_name: "text_content",
content_type_name: "content_type"
},
data: {
body_name: "data",
content_type_name: "content_type"
}
}, },
sub_storage: get_jio_cache_storage(name) sub_storage: get_jio_cache_storage(name)
}, },
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.30941.12978.18978</string> </value> <value> <string>953.36709.37743.20718</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1472135853.24</float> <float>1472479075.38</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -51,12 +51,24 @@ var global = self, ...@@ -51,12 +51,24 @@ var global = self,
// 2. readonly cache for end user // 2. readonly cache for end user
self.jio_erp5_cache_storage = { self.jio_erp5_cache_storage = {
type: "query", type: "memoryindex",
select_list: ['reference', 'url_string'],
index: {
url_string: null,
reference: function (obj) {
if (!obj.url_string) {
return obj.reference;
}
}
},
sub_storage: { sub_storage: {
type: "uuid", type: "query",
sub_storage: { sub_storage: {
type: "indexeddb", type: "uuid",
database: self.jio_cache.name + '_erp5' sub_storage: {
type: "indexeddb",
database: self.jio_cache.name + '_erp5'
}
} }
} }
}; };
...@@ -196,12 +208,13 @@ var global = self, ...@@ -196,12 +208,13 @@ var global = self,
storage = self.jio_cache_storage; storage = self.jio_cache_storage;
} }
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
storage.get(jio_key) storage.getAttachment(jio_key, 'body')
.push(function (metadata) { .push(function (body) {
return storage.getAttachment(jio_key, 'body') resolve(new Response(body, {
.push(function (body) { 'headers': {
resolve(new Response(body, {'headers': metadata.headers})); 'content-type': body.type
}); }
}));
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
reject(error); reject(error);
...@@ -227,15 +240,15 @@ var global = self, ...@@ -227,15 +240,15 @@ var global = self,
if (!storage) { if (!storage) {
storage = self.jio_dev_storage; storage = self.jio_dev_storage;
} }
query.limit = [0, 1];
query.select_list = ['portal_type'];
return storage.allDocs(query) return storage.allDocs(query)
.push(function (result) { .push(function (result) {
if (result.data.total_rows >= 1) { if (result.data.total_rows == 1) {
var id = result.data.rows[0].id; return {
return storage.get(id) id: result.data.rows[0].id,
.push(function (doc) { portal_type: result.data.rows[0].value.portal_type
doc.id = id; };
return doc;
});
} else { } else {
throw {status_code: 404}; throw {status_code: 404};
} }
...@@ -244,6 +257,7 @@ var global = self, ...@@ -244,6 +257,7 @@ var global = self,
get_from_storage = function (url, storage) { get_from_storage = function (url, storage) {
var url_string = get_specific_url(url), var url_string = get_specific_url(url),
url_object = new URI(url), url_object = new URI(url),
key,
reference = url_object.filename(); reference = url_object.filename();
if (!storage) { if (!storage) {
storage = self.jio_dev_storage; storage = self.jio_dev_storage;
...@@ -251,50 +265,25 @@ var global = self, ...@@ -251,50 +265,25 @@ var global = self,
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
var find_queue; var find_queue;
if (url_string !== undefined) { if (url_string !== undefined) {
find_queue = find_and_get({ key = storage.__storage._find_key('url_string', url_string);
query: query_portal_types + ' AND (url_string: ="' + url_string + '")' //if (!self.jio_cache.development_mode && !key) {
}, storage); // key = storage.__storage._find_key('reference', reference);
if (!self.jio_cache.development_mode) { //}
find_queue = find_queue
.push(undefined, function (error) {
if (error.status_code === 404) {
return find_and_get({
query: query_portal_types + ' AND (reference: ="' + reference + '")',
sort_on: [["url_string", "ascending"]]
}, storage);
} else {
throw error;
}
});
}
//} else if (reference !== "") {
} else if (reference === get_relative_url(url)) { } else if (reference === get_relative_url(url)) {
// i use sort_on for emulate query: key = storage.__storage._find_key('reference', reference);
// '(url_string: "" ) AND (reference: "' + reference + '")' }
find_queue = find_and_get({ if (!key) {
query: query_portal_types + ' AND (reference: ="' + reference + '")',
sort_on: [["url_string", "ascending"]]
}, storage);
} else {
reject({status_code: 404}); reject({status_code: 404});
return; return;
} }
find_queue find_queue = storage.getAttachment(key, 'text_content')
.push(function (doc) {
return storage.getAttachment(doc.id, portal_type2attach_name(doc.portal_type))
.push(function (body) { .push(function (body) {
var content_type;
content_type = doc.content_type;
if (content_type === undefined) {
content_type = map_portal_type2content_type[doc.portal_type];
}
resolve(new Response(body, { resolve(new Response(body, {
'headers': { 'headers': {
'content-type': content_type 'content-type': body.type
} }
})); }));
}); })
})
.push(undefined, function (error) { .push(undefined, function (error) {
reject(error); reject(error);
}); });
......
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.27011.49620.36881</string> </value> <value> <string>953.37175.9141.55876</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1471898009.02</float> <float>1472507149.74</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -324,7 +324,7 @@ ...@@ -324,7 +324,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1461754648.25</float> <float>1461754648.2</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
web_page = context
portal_type = web_page.getPortalType()
content_type = web_page.getContentType()
if not content_type:
if (portal_type == "Web Script"):
content_type = 'application/javascript'
elif (portal_type == "Web Style"):
content_type = 'text/css'
elif (portal_type == "Web Page"):
content_type = 'text/html'
return content_type
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebPage_getContentType</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
<string>my_portal_type</string> <string>my_portal_type</string>
<string>your_modification_date</string> <string>your_modification_date</string>
<string>my_url_string</string> <string>my_url_string</string>
<string>my_content_type</string>
</list> </list>
</value> </value>
</item> </item>
......
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