From 3e367df7248421ebd437dddf84b99bf346ae0d0b Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Mon, 12 Oct 2026 10:09:20 +0200 Subject: [PATCH] reduce ci time (#12985) * we are currently locking on olugin lease for 2 mins per ci setup; not good * fix syntax * move setting * fix assign syntax * reduce noice while setting up --- .github/actions/migration/action.yaml | 2 ++ .github/actions/setup/action.yaml | 9 +++++++++ src/backend/InvenTree/InvenTree/settings.py | 1 + src/backend/InvenTree/plugin/lease.py | 4 ++-- src/backend/InvenTree/plugin/registry.py | 10 ++++++++-- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/actions/migration/action.yaml b/.github/actions/migration/action.yaml index 2c06172153..4a2aee0c7c 100644 --- a/.github/actions/migration/action.yaml +++ b/.github/actions/migration/action.yaml @@ -15,3 +15,5 @@ runs: invoke migrate invoke import-records -c -f data.json --strict invoke import-records -c -f data.json --strict + env: + SETUP_INITIALIZING: 1 diff --git a/.github/actions/setup/action.yaml b/.github/actions/setup/action.yaml index 6000656c31..15445fbe08 100644 --- a/.github/actions/setup/action.yaml +++ b/.github/actions/setup/action.yaml @@ -37,6 +37,7 @@ inputs: runs: using: 'composite' + steps: - name: Checkout Code uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -97,15 +98,23 @@ runs: if: ${{ inputs.dev-install == 'true' || inputs.install == 'true' }} shell: bash run: invoke install --dev + env: + SETUP_INITIALIZING: 1 - name: Run invoke install if: ${{ inputs.install == 'true' }} shell: bash run: invoke install + env: + SETUP_INITIALIZING: 1 - name: Run invoke update if: ${{ inputs.update == 'true' }} shell: bash run: invoke update --skip-backup --skip-static --no-frontend + env: + SETUP_INITIALIZING: 1 - name: Collect static files if: ${{ inputs.static == 'true' }} shell: bash run: invoke static --skip-plugins + env: + SETUP_INITIALIZING: 1 diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index 073a83a242..24a2264d79 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -235,6 +235,7 @@ PLUGIN_TESTING_SETUP = get_setting( PLUGIN_TESTING_EVENTS = False # Flag if events are tested right now PLUGIN_TESTING_EVENTS_ASYNC = False # Flag if events are tested asynchronously PLUGIN_TESTING_RELOAD = False # Flag if plugin reloading is in testing (check_reload) +SETUP_INITIALIZING = os.environ.get('SETUP_INITIALIZING', '0') == '1' # Plugin development settings PLUGIN_DEV_SLUG = get_setting('INVENTREE_PLUGIN_DEV_SLUG', 'plugin_dev.slug') diff --git a/src/backend/InvenTree/plugin/lease.py b/src/backend/InvenTree/plugin/lease.py index 6dfa53144a..5af423a386 100644 --- a/src/backend/InvenTree/plugin/lease.py +++ b/src/backend/InvenTree/plugin/lease.py @@ -4,11 +4,11 @@ Used to serialize an potentially long-running operation, without holding a database transaction open for the duration. """ -import os import time from datetime import datetime, timedelta from typing import Optional +from django.conf import settings from django.db import transaction from django.db.utils import IntegrityError, OperationalError, ProgrammingError from django.utils import timezone @@ -82,7 +82,7 @@ def acquire_lease_blocking( """ deadline = time.monotonic() + timeout - if os.environ.get('SETUP_INITIALIZING', '0') == '1': + if settings.SETUP_INITIALIZING: logger.debug("Skipping lease acquisition for '%s' during initialization", key) return True diff --git a/src/backend/InvenTree/plugin/registry.py b/src/backend/InvenTree/plugin/registry.py index a9337c9ac1..416b087a32 100644 --- a/src/backend/InvenTree/plugin/registry.py +++ b/src/backend/InvenTree/plugin/registry.py @@ -227,6 +227,10 @@ class PluginsRegistry: dict[str, PluginConfig]: Mapping of plugin slug to PluginConfig instance. None if the database is not ready to be queried. """ + # skip if the setup is initializing + if settings.SETUP_INITIALIZING: + return None + # As we have already checked the registry hash, this is a valid cache key cache_key = f'plugin_configs:{self.registry_hash}' @@ -518,8 +522,10 @@ class PluginsRegistry: self.update_plugin_hash() logger.info('Plugin Registry: Loaded %s plugins', len(self.plugins)) - # Ensure that each loaded plugin has a valid configuration object in the database - for plugin in self.plugins.values(): + # Ensure that each loaded plugin has a valid configuration object in the database; skip if setup is initializing + for plugin in ( + self.plugins.values() if not settings.SETUP_INITIALIZING else [] + ): if config := self.get_plugin_config(plugin.slug): # Ensure mandatory plugins are marked as active if config.is_mandatory() and not config.active: