Avoid SQL update on blog post view
leoholz opened this issue · comments
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?
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.
Can i work on this ?