stephenmcd / mezzanine

CMS framework for Django
http://mezzanine.jupo.org
BSD 2-Clause "Simplified" License
4.76k stars 1.65k forks source link

Avoid SQL update on blog post view #1963

Open leoholz opened 4 years ago

leoholz commented 4 years ago

Hi there! During rendering of a blog post page Mezzanine writes back the whole blog post to the database: UPDATE "blog_blogpost" SET ... Actually I cannot see changes in the blog post content.

For my current setup it would be very helpful to load the page without generating a write. Is there a way to do this? Or can someone explain why it happens so I can modify the source if necessary?

leoholz commented 4 years ago

Ok, I found the problem. The write is caused by the automatic short URL creation in core/models.py:

    def set_short_url(self):
        if not self.short_url or self.short_url == SHORT_URL_UNSET:
            self.short_url = self.generate_short_url()
            self.save()
        if self.short_url == SHORT_URL_UNSET:
            self.short_url = self.get_absolute_url_with_host()

In the case that self.generate_short_url() returns SHORT_URL_UNSET, self.save() is called at every request. It would be great to call self.save() only when short_url has an updated value.

GOUTHAM-2002 commented 3 months ago

Can i work on this ?