summaryrefslogtreecommitdiff
path: root/background/reverse_use_info.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'background/reverse_use_info.mjs')
-rw-r--r--background/reverse_use_info.mjs93
1 files changed, 0 insertions, 93 deletions
diff --git a/background/reverse_use_info.mjs b/background/reverse_use_info.mjs
deleted file mode 100644
index c38c52f..0000000
--- a/background/reverse_use_info.mjs
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
-* Myext scripts and bundles usage index
-*
-* Copyright (C) 2021 Wojtek Kosior
-*
-* Dual-licensed under:
-* - 0BSD license
-* - GPLv3 or (at your option) any later version
-*/
-
-import TYPE_PREFIX from '/common/stored_types.mjs';
-import get_storage from './storage.mjs';
-import make_once from '/common/once.mjs';
-
-"use strict";
-
-/*
- * We want to count referenes to scripts and bundles in order to know,
- * for example, whether one can be safely deleted.
- */
-
-var component_uses = new Map();
-var storage;
-
-function add_use_info_by_item(prefix, item, components)
-{
- for (let component of components) {
- component = component.join("");
-
- let used_by_info = component_uses.get(component);
-
- if (used_by_info === undefined) {
- used_by_info = {};
- component_uses.set(component, used_by_info);
- }
-
- if (used_by_info[prefix] === undefined)
- used_by_info[prefix] = new Set();
-
- used_by_info[prefix].add(item);
- }
-}
-
-function remove_use_info_by_item(prefix, item, components)
-{
- for (let component of components) {
- used_by_info = component_uses.get(component.join(""));
- if (used_by_info === undefined || used_by_info[prefix] === undefined)
- return;
-
- used_by_info[prefix].delete(item);
- }
-}
-
-function build_reverse_uses_info(entries_it, type_prefix)
-{
- for (let [item, components] of storage.get_all_it(type_prefix))
- add_use_info_by_item(type_prefix, item, components);
-}
-
-function handle_change(change)
-{
- if (change.old_val !== undefined)
- remove_use_info_by_item(change.prefix, change.item, change.old_val);
-
- if (change.new_val !== undefined)
- add_use_info_by_item(change.prefix, change.item, change.new_val);
-}
-
-function get_uses(arg1, arg2=undefined)
-{
- let [prefix, item] = [arg1, arg2];
-
- if (arg2 === undefined)
- [prefix, item] = arg1;
-
- return component_uses.get(prefix + item);
-}
-
-async function init()
-{
- storage = await get_storage();
-
- prefixes = [TYPE_PREFIX.PAGE, TYPE_PREFIX.BUNDLE];
- for (let prefix of prefixes)
- build_reverse_uses_info(prefix);
-
- storage.add_change_listener(handle_change, prefixes);
-
- return get_uses;
-}
-
-export default make_once(init);