Skip to content

Commit

Permalink
Override the default save method of ``EnterpriseCustomerPluginConfigu…
Browse files Browse the repository at this point in the history
…ration`` to update only changed fields (#1960)

* refactor: change save method of EnterpriseCustomerPluginConfiguration to update only changed fields
  • Loading branch information
zamanafzal authored Dec 6, 2023
1 parent 908ea59 commit 6a59a2c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Change Log
Unreleased
----------
[4.8.7]
--------
refactor: Override the default save method of ``EnterpriseCustomerPluginConfiguration`` to update only changed fields

[4.8.6]
--------
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.8.6"
__version__ = "4.8.7"
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def update_config_last_errored_at(self):
config.id, channel_code, config.enterprise_customer.uuid
)
)
config.save()
config.save(update_fields=["last_learner_sync_errored_at", "last_content_sync_errored_at",
"last_sync_errored_at"])

except Exception as exc:
LOGGER.exception('update_config_last_errored_at', exc_info=exc)
raise exc
Expand Down
20 changes: 18 additions & 2 deletions integrated_channels/integrated_channel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,31 +273,47 @@ def update_content_synced_at(self, action_happened_at, was_successful):
"""
Given the last time a Content record sync was attempted and status update the appropriate timestamps.
"""
update_fields = []
if self.last_sync_attempted_at is None or action_happened_at > self.last_sync_attempted_at:
self.last_sync_attempted_at = action_happened_at
update_fields.append('last_sync_attempted_at')
if self.last_content_sync_attempted_at is None or action_happened_at > self.last_content_sync_attempted_at:
self.last_content_sync_attempted_at = action_happened_at
update_fields.append('last_content_sync_attempted_at')
if not was_successful:
if self.last_sync_errored_at is None or action_happened_at > self.last_sync_errored_at:
self.last_sync_errored_at = action_happened_at
update_fields.append('last_sync_errored_at')
if self.last_content_sync_errored_at is None or action_happened_at > self.last_content_sync_errored_at:
self.last_content_sync_errored_at = action_happened_at
return self.save()
update_fields.append('last_content_sync_errored_at')
if update_fields:
return self.save(update_fields=update_fields)
else:
return self

def update_learner_synced_at(self, action_happened_at, was_successful):
"""
Given the last time a Learner record sync was attempted and status update the appropriate timestamps.
"""
update_fields = []
if self.last_sync_attempted_at is None or action_happened_at > self.last_sync_attempted_at:
self.last_sync_attempted_at = action_happened_at
update_fields.append('last_sync_attempted_at')
if self.last_learner_sync_attempted_at is None or action_happened_at > self.last_learner_sync_attempted_at:
self.last_learner_sync_attempted_at = action_happened_at
update_fields.append('last_learner_sync_attempted_at')
if not was_successful:
if self.last_sync_errored_at is None or action_happened_at > self.last_sync_errored_at:
self.last_sync_errored_at = action_happened_at
update_fields.append('last_sync_errored_at')
if self.last_learner_sync_errored_at is None or action_happened_at > self.last_learner_sync_errored_at:
self.last_learner_sync_errored_at = action_happened_at
return self.save()
update_fields.append('last_learner_sync_errored_at')
if update_fields:
return self.save(update_fields=update_fields)
else:
return self

@property
def is_valid(self):
Expand Down

0 comments on commit 6a59a2c

Please sign in to comment.