From a83823969615a449425faf59569376247223fbc2 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 2 Oct 2023 13:45:13 +0200 Subject: [PATCH] source: do not fire a configured event again if nothing changed When handling a POST request to /source, Subiquity sends a 'source configured' event. This signals other controllers / models that they need to restart their tasks that depend on the source being used. However, if the user of the installer goes back all the way to the source page and submits it again without changing the settings, there should be no reason to restart the machinery. If a call to source ends up doing no modification to the model (i.e., not changing the source used or the search_drivers setting), we now avoid emitting the 'source configured' event ; except if the model has not been configured yet. Signed-off-by: Olivier Gayot --- subiquity/server/controllers/source.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/subiquity/server/controllers/source.py b/subiquity/server/controllers/source.py index c2e41f6eb1..3a8da05339 100644 --- a/subiquity/server/controllers/source.py +++ b/subiquity/server/controllers/source.py @@ -79,6 +79,7 @@ def __init__(self, app): self._handler = None self.source_path: Optional[str] = None self.ai_source_id: Optional[str] = None + self._configured: bool = False def make_autoinstall(self): return { @@ -148,10 +149,24 @@ def get_handler( async def configured(self): await super().configured() + self._configured = True self.app.base_model.set_source_variant(self.model.current.variant) async def POST(self, source_id: str, search_drivers: bool = False) -> None: - self.model.search_drivers = search_drivers + # Marking the source model configured has an effect on many of the + # other controllers. Oftentimes, it would involve cancelling and + # restarting various operations. + # Let's try not to trigger the event again if we are not changing any + # of the settings. + changed = False + if search_drivers != self.model.search_drivers: + changed = True + self.model.search_drivers = search_drivers with contextlib.suppress(KeyError): - self.model.current = self.model.get_matching_source(source_id) - await self.configured() + new_source = self.model.get_matching_source(source_id) + if new_source != self.model.current: + changed = True + self.model.current = new_source + + if changed or not self._configured: + await self.configured()