diff --git a/CHANGELOG.md b/CHANGELOG.md index 80a91db..e51e053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Remember tree position in menus - Show hidden server count after filtering - Atomic map filters per server context +- Use concurrency when checking stale mods (performance uplift) ## Changed - Reduce padding on keys button diff --git a/dzgui/api/mods.py b/dzgui/api/mods.py index 81ce751..9010079 100644 --- a/dzgui/api/mods.py +++ b/dzgui/api/mods.py @@ -3,6 +3,8 @@ import hashlib import logging import shlex +from concurrent.futures import wait +from concurrent.futures import ThreadPoolExecutor from dataclasses import dataclass from pathlib import Path @@ -145,26 +147,30 @@ def remove_stale_signatures(config: Path, versions: Path) -> None: for line in lines: f.write(line) - def find_stale_mods(config: Path) -> list[int]: + def push_record(rec: str) -> list: + add = rec.split(":") + ip = add[0] + qport = add[2] + return get_rules(ip, qport) + steam = lookup(config, Preferences.DEFAULT) steam_path = Path(steam) - # TODO: use concurrency local = get_local_mod_ids(steam_path) - servers = lookup(config, Preferences.IP_LIST) + records = lookup(config, Preferences.IP_LIST) - all_mods = [] - for server in servers: - split = server.split(":") - ip = split[0] - qport = split[2] + remote_mods = [] - mods = get_rules(ip, qport) - all_mods += mods + with ThreadPoolExecutor() as executor: + futures = [ + executor.submit(push_record, record) + for record in records + ] + wait(futures) + for future in futures: + res = future.result() + remote_mods += res - stale = [] - for mod in local: - if mod not in all_mods: - stale.append(mod) + stale = [mod for mod in local if mod not in remote_mods] return stale diff --git a/dzgui/controllers/mc.py b/dzgui/controllers/mc.py index 2ea5621..510ccba 100644 --- a/dzgui/controllers/mc.py +++ b/dzgui/controllers/mc.py @@ -596,6 +596,7 @@ class Controller(GObject.GObject): it = mod.iter path = model.get_path(it) # TODO: consider storing in ListStore as int + # TODO: clone existing model and set outside of thread if int(mod[2]) in stale: model[path][4] = HEX_RED @@ -731,7 +732,7 @@ class Controller(GObject.GObject): func = self.get_callback() self.mediator.window.set_sensitive(True) # TODO: spawn error dialog if API crawl failed - # most likely going to drop this + # most likely going to drop callback method if func is not None: args = self.get_callback_args() GLib.idle_add(func, *args) diff --git a/dzgui/data/CHANGELOG.md b/dzgui/data/CHANGELOG.md index 80a91db..e51e053 100644 --- a/dzgui/data/CHANGELOG.md +++ b/dzgui/data/CHANGELOG.md @@ -24,6 +24,7 @@ - Remember tree position in menus - Show hidden server count after filtering - Atomic map filters per server context +- Use concurrency when checking stale mods (performance uplift) ## Changed - Reduce padding on keys button