module_loader: Don't load modules again

- Only effective once. Second call will skip loading modules.

- Helps with privileged daemon where actions might load modules repeatedly.

Tests:

- Diagnostics/enable/disable for apps bepasty, updates, config, security,
  nextcloud, homeassistant run fine.
- Install/uninstall for bepasty works fine.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
Sunil Mohan Adapa 2025-06-26 18:23:38 -07:00 committed by Joseph Nuthalapati
parent 4220511eb7
commit e100c89ecc
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35

View File

@ -7,6 +7,7 @@ import importlib
import logging
import pathlib
import re
import types
import django
@ -15,7 +16,7 @@ from plinth.signals import pre_module_loading
logger = logging.getLogger(__name__)
loaded_modules = dict()
loaded_modules: dict[str, types.ModuleType] = dict()
_modules_to_load = None
@ -31,6 +32,9 @@ def load_modules():
Read names of enabled modules in modules/enabled directory and
import them from modules directory.
"""
if loaded_modules:
return # Modules have already been loaded
pre_module_loading.send_robust(sender="module_loader")
for module_import_path in get_modules_to_load():
module_name = module_import_path.split('.')[-1]