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 @@
local_sub_storage: {
type: "attachasproperty",
map: {
text_content: "text_content",
data: "data"
text_content: {
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)
},
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.30941.12978.18978</string> </value>
<value> <string>953.36709.37743.20718</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1472135853.24</float>
<float>1472479075.38</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -51,12 +51,24 @@ var global = self,
// 2. readonly cache for end user
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: {
type: "uuid",
type: "query",
sub_storage: {
type: "indexeddb",
database: self.jio_cache.name + '_erp5'
type: "uuid",
sub_storage: {
type: "indexeddb",
database: self.jio_cache.name + '_erp5'
}
}
}
};
......@@ -196,12 +208,13 @@ var global = self,
storage = self.jio_cache_storage;
}
return new Promise(function (resolve, reject) {
storage.get(jio_key)
.push(function (metadata) {
return storage.getAttachment(jio_key, 'body')
.push(function (body) {
resolve(new Response(body, {'headers': metadata.headers}));
});
storage.getAttachment(jio_key, 'body')
.push(function (body) {
resolve(new Response(body, {
'headers': {
'content-type': body.type
}
}));
})
.push(undefined, function (error) {
reject(error);
......@@ -227,15 +240,15 @@ var global = self,
if (!storage) {
storage = self.jio_dev_storage;
}
query.limit = [0, 1];
query.select_list = ['portal_type'];
return storage.allDocs(query)
.push(function (result) {
if (result.data.total_rows >= 1) {
var id = result.data.rows[0].id;
return storage.get(id)
.push(function (doc) {
doc.id = id;
return doc;
});
if (result.data.total_rows == 1) {
return {
id: result.data.rows[0].id,
portal_type: result.data.rows[0].value.portal_type
};
} else {
throw {status_code: 404};
}
......@@ -244,6 +257,7 @@ var global = self,
get_from_storage = function (url, storage) {
var url_string = get_specific_url(url),
url_object = new URI(url),
key,
reference = url_object.filename();
if (!storage) {
storage = self.jio_dev_storage;
......@@ -251,50 +265,25 @@ var global = self,
return new Promise(function (resolve, reject) {
var find_queue;
if (url_string !== undefined) {
find_queue = find_and_get({
query: query_portal_types + ' AND (url_string: ="' + url_string + '")'
}, storage);
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 !== "") {
key = storage.__storage._find_key('url_string', url_string);
//if (!self.jio_cache.development_mode && !key) {
// key = storage.__storage._find_key('reference', reference);
//}
} else if (reference === get_relative_url(url)) {
// i use sort_on for emulate query:
// '(url_string: "" ) AND (reference: "' + reference + '")'
find_queue = find_and_get({
query: query_portal_types + ' AND (reference: ="' + reference + '")',
sort_on: [["url_string", "ascending"]]
}, storage);
} else {
key = storage.__storage._find_key('reference', reference);
}
if (!key) {
reject({status_code: 404});
return;
}
find_queue
.push(function (doc) {
return storage.getAttachment(doc.id, portal_type2attach_name(doc.portal_type))
find_queue = storage.getAttachment(key, 'text_content')
.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, {
'headers': {
'content-type': content_type
'content-type': body.type
}
}));
});
})
})
.push(undefined, function (error) {
reject(error);
});
......
......@@ -249,7 +249,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.27011.49620.36881</string> </value>
<value> <string>953.37175.9141.55876</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -267,7 +267,7 @@
</tuple>
<state>
<tuple>
<float>1471898009.02</float>
<float>1472507149.74</float>
<string>UTC</string>
</tuple>
</state>
......@@ -324,7 +324,7 @@
</tuple>
<state>
<tuple>
<float>1461754648.25</float>
<float>1461754648.2</float>
<string>UTC</string>
</tuple>
</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 @@
<string>my_portal_type</string>
<string>your_modification_date</string>
<string>my_url_string</string>
<string>my_content_type</string>
</list>
</value>
</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