Skip to content

Commit

Permalink
feat: Pre-populate version.content cache when getting version for c…
Browse files Browse the repository at this point in the history
…ontent
  • Loading branch information
fsbraun committed Jan 27, 2025
1 parent f68190c commit c13f8ac
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions djangocms_versioning/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def get_for_content(self, content_object):
version = self.get(
object_id=content_object.pk, content_type__in=versionable.content_types
)
version._state.fields_cache['content'] = content_object

Check failure on line 54 in djangocms_versioning/models.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (Q000)

djangocms_versioning/models.py:54:37: Q000 Single quotes found but double quotes preferred

Check failure on line 54 in djangocms_versioning/models.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (Q000)

djangocms_versioning/models.py:54:37: Q000 Single quotes found but double quotes preferred
content_object._version_cache = version
return version

Expand Down Expand Up @@ -243,8 +244,12 @@ def convert_to_proxy(self):
"""Returns a copy of current Version object, but as an instance
of its correct proxy model"""

cache = self._state.fields_cache
del self._state.fields_cache # Remove cache before creating deep copying
new_obj = copy.deepcopy(self)
new_obj.__class__ = self.versionable.version_model_proxy
new_obj._state.fields_cache = cache # Recover caches
self._state.fields_cache = cache # Recover caches
return new_obj

@property
Expand Down

0 comments on commit c13f8ac

Please sign in to comment.