etianen / django-reversion

django-reversion is an extension to the Django web framework that provides version control for model instances.
https://django-reversion.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.05k stars 489 forks source link

Admin: 'GET' on a change_view creates a transaction block #940

Closed gersmann closed 1 year ago

gersmann commented 1 year ago

I noticed that loading change_view pages is slower when using reversion, due to a transaction block being opened. If I replace the implementation of create_revision with:

    @contextmanager
    def create_revision(self, request: HttpRequest):
        if request.method == "GET":
            yield
        else:
            with create_revision():
                set_user(request.user)
                yield

This goes away. Is there a reason for wrapping change_view GET requests in a create_revision block?

etianen commented 1 year ago

Good idea.

I'd take a PR to use _request_creates_revision to conditionally create the revision in the admin.