Skip to content

Commit 04deae0

Browse files
committed
chore(controller): optimize app refresh timing
1 parent 3c8d76e commit 04deae0

3 files changed

Lines changed: 11 additions & 25 deletions

File tree

rootfs/api/models/appsettings.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ def save(self, *args, **kwargs):
177177
if not self.summary and previous_settings:
178178
self.delete()
179179
raise AlreadyExists("{} changed nothing".format(self.owner))
180-
181180
summary = ' '.join(self.summary)
182-
try:
183-
return super(AppSettings, self).save(**kwargs)
184-
finally:
185-
# Read and write are separated, in transaction the read database is not updated
186-
self.app.refresh(app_settings=self)
187181
self.app.log('summary of app setting changes: {}'.format(summary), logging.DEBUG)
182+
super(AppSettings, self).save(**kwargs)
183+
# Read and write are separated, in transaction the read database is not updated
184+
self.app.refresh(app_settings=self)

rootfs/api/models/domain.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,25 @@ class Meta:
2727

2828
@transaction.atomic
2929
def save(self, *args, **kwargs):
30+
super(Domain, self).save(*args, **kwargs)
31+
# Read and write are separated, in transaction the read database is not updated
3032
domains = list(self.app.domain_set.all())
31-
# certificate attach update domains
3233
if self in domains:
3334
domains.remove(self)
3435
domains.append(self)
35-
try:
36-
# Save to DB
37-
return super(Domain, self).save(*args, **kwargs)
38-
finally:
39-
# Read and write are separated, in transaction the read database is not updated
40-
self.app.refresh(domains=domains)
36+
self.app.refresh(domains=domains)
4137

4238
@transaction.atomic
4339
def delete(self, *args, **kwargs):
4440
# Deatch cert, updates k8s
4541
if self.certificate:
4642
self.certificate.detach(domain=str(self.domain))
43+
super(Domain, self).delete(*args, **kwargs)
44+
# Read and write are separated, in transaction the read database is not updated
4745
domains = list(self.app.domain_set.all())
4846
if self in domains:
4947
domains.remove(self)
50-
try:
51-
# Delete from DB
52-
return super(Domain, self).delete(*args, **kwargs)
53-
finally:
54-
# Read and write are separated, in transaction the read database is not updated
55-
self.app.refresh(domains=domains)
48+
self.app.refresh(domains=domains)
5649

5750
def __str__(self):
5851
return self.domain

rootfs/api/models/tls.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@ def _check_previous_tls_settings(self):
4545
@transaction.atomic
4646
def save(self, *args, **kwargs):
4747
self._check_previous_tls_settings()
48-
try:
49-
# Save to DB
50-
return super(TLS, self).save(*args, **kwargs)
51-
finally:
52-
# Read and write are separated, in transaction the read database is not updated
53-
self.app.refresh(tls=self)
48+
super(TLS, self).save(*args, **kwargs)
49+
self.sync()
5450

5551
def sync(self):
5652
# Read and write are separated, in transaction the read database is not updated

0 commit comments

Comments
 (0)