Skip to content

Caching the version.previous attribute #290

Closed

Description

@AbdealiLoKo

Currently, the version.previous attribute is calling VersionObjectFetcher.previous
Which runs: self.previous_query(obj).first()

Because it is using .first() - a query is running every time.

It would be a nice developer experience to cache this so it does not call multiple queries.

Currently I need to do:

current = ...
previous = current.previous

And then pass it all around in my functions to avoid performance issues.
It would make my code a lot simpler if the previous property cached the value so I did not need to save it in my own separate variable

Activity

  1. josecsotomorales commented on Oct 15, 2026

    @josecsotomorales
    Collaborator

    Added in 1.6.0 (#376): ArticleVersion.all_versions(session, {'id': article.id}) loads the whole history in one query and pre-fills previous/next, so walking it doesn't run extra queries. See the batch-fetching section of the query docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions