Skip to content

Commit

Permalink
Merge pull request #1814 from ogayot/noop-no-emit-source-configured
Browse files Browse the repository at this point in the history
source: do not fire a configured event again if nothing changed
  • Loading branch information
dbungert authored Oct 5, 2023
2 parents 2970912 + f6da616 commit d4e9f7d
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions subiquity/server/controllers/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import contextlib
import logging
import os
from typing import Any, Optional
Expand Down Expand Up @@ -79,6 +78,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 {
Expand Down Expand Up @@ -148,10 +148,31 @@ 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
with contextlib.suppress(KeyError):
self.model.current = self.model.get_matching_source(source_id)
await self.configured()
# 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 self.model.search_drivers != search_drivers:
changed = True
self.model.search_drivers = search_drivers

try:
new_source = self.model.get_matching_source(source_id)
except KeyError:
# TODO going forward, we should probably stop ignoring unmatched
# sources.
log.warning("unable to find '%s' in sources catalog", source_id)
pass
else:
if self.model.current != new_source:
changed = True
self.model.current = new_source

if changed or not self._configured:
await self.configured()

0 comments on commit d4e9f7d

Please sign in to comment.