gouthambs / Flask-Blogging

A Markdown Based Python Blog Engine as a Flask Extension.
http://flask-blogging.readthedocs.org/en/latest/
MIT License
688 stars 159 forks source link

Reduce query count #119

Closed raoulsullivan closed 6 years ago

raoulsullivan commented 6 years ago

Hi,

I was optimising site performance when I noticed that flask-blogging emits a lot of database queries, particularly on the index and sitemap views.

The following PR attempts to remedy that by joining the post, tag_posts, tag and user_posts table in both the get_posts and get_post_by_id methods. This results in moving the responsibility for joining posts to tags from the database to the Python.

The PR also changes from Flask-Cache to flask-caching to overcome this issue.

Enjoy!

gouthambs commented 6 years ago

Thanks @raoulsullivan . I will take a look later today and merge.

gouthambs commented 6 years ago

@raoulsullivan I merged your changes to master and noticed that the MySQL test fails. Do you have any thoughts?

https://travis-ci.org/gouthambs/Flask-Blogging/jobs/427514097

raoulsullivan commented 6 years ago

Yeah, my thought is that I need to do a bit more work! The problem is almost certainly with the ordering of the results when joining the data together, which I remedied for my setup (postgres).

Will spin up a mysql database now and update here.

raoulsullivan commented 6 years ago

Addressed in https://github.com/gouthambs/Flask-Blogging/pull/120