Commit e4d5fbf8 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: Use generate unique id for pages

built index many time should not add the same page again in the idexeddb. Unique Id is generated from the page URL
parent 933ebfd7
......@@ -14,8 +14,15 @@
.getElementById("build-template-progress")
.innerHTML);
function get_random_id() {
return '_' + Math.random().toString(36).substr(2, 9);
function hashCodeInt(s) {
return s.split("").reduce(function (a, b) {
a = ((a<<5) - a) + b.charCodeAt(0);
return a&a;
}, 0);
}
function hashCode(s) {
return "" + hashCodeInt(s);
}
function showError(error_message) {
......@@ -266,7 +273,7 @@
if (!item.link || item.link.includes("https://localhost:"))
item.link = "no-link";
promise_list.push(gadget.add_to_index({
id : get_random_id(),
id : hashCode(item.link),
link : item.link,
title : item.title,
content : item.content
......@@ -371,7 +378,8 @@
title = "",
tmp_div,
content,
result;
result,
link;
regex = page.currentTarget.response.match(/<title[^>]*>([^<]+)<\/title>/);
if (regex)
title = regex[1];
......@@ -391,9 +399,10 @@
}
if (!tmp_div)
return;
link = new URL(page.currentTarget.responseURL).searchParams.get('url');
result = {
id : get_random_id(),
link : page.currentTarget.responseURL.slice(proxies[0].length),
id : hashCode(link),
link : link,
title : title,
content : tmp_div.textContent || tmp_div.innerText || ""
};
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>990.2403.64322.7168</string> </value>
<value> <string>990.3475.54016.22254</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1613405732.81</float>
<float>1613470010.32</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -48,9 +48,6 @@
list = document.getElementById("mynij-results");
list_item = document.createElement("li");
list_item.id = Math.random().toString(36) + '-' + Date.now();
if (item.link.startsWith("?url=")) {
item.link = item.link.substring(5);
}
return gadget.cut_link(item.link)
.push(function (cut_link) {
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.6677.22006.33024</string> </value>
<value> <string>989.10151.37063.11315</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1609937733.92</float>
<float>1613470052.64</float>
<string>UTC</string>
</tuple>
</state>
......
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