MCPcopy Index your code
hub / github.com/NobyDa/Script / saveDecision

Function saveDecision

Rule-Storage/Rule-Storage.js:51–80  ·  view source on GitHub ↗
(host_name, content = {})

Source from the content-addressed store, hash-verified

49 .finally(() => $done({ matched: Boolean(args.matched) }));
50
51function saveDecision(host_name, content = {}) {
52 const count = [];
53 for (const i in content) {
54 if (Date.now() - content[i].update_time > 86400000 * (args.cacheDays || 30)) {
55 delete content[i];
56 continue
57 }
58 count.push(content[i].update_time);
59 }
60 if (count.length > (args.cacheNumber || 1000)) { // limit amount to prevent NE memory issues.
61 const spill = count.sort((x, y) => x - y).slice(0, count.length - (args.cacheNumber || 1000));
62 for (const is of spill) {
63 for (const ic in content) {
64 if (content[ic].update_time === is) {
65 delete content[ic];
66 break
67 }
68 }
69 }
70 }
71 if (content[host_name]) {
72 if (Date.now() - content[host_name].update_time > ((args.interval || 30) * 1000)) {
73 content[host_name].update_time = Date.now();
74 content[host_name].quantity++;
75 }
76 } else {
77 content[host_name] = { update_time: Date.now(), quantity: 1 }
78 }
79 return content
80}
81
82function evalRules(host_name, rule_list) {
83 const host_suffix = host_name.split('.').reverse();

Callers 1

Rule-Storage.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected