I have a site that on some pages iterates over events, creating email and
facebook share links. These links are created via models on the method,
i.e.:
def facebook_share_url(self):
settings.use_editable()
request = current_request()
host = request.get_host()
if self.featured_image:
image = '%s%s%s' % (host, settings.MEDIA_URL, self.featured_image)
else:
image = ''
full_path = host + self.get_absolute_url()
link = "https://www.facebook.com/dialog/feed?app_id=" +
settings.FACEBOOK_APP_ID + "&link=http%3A%2F%2F" + full_path +
"&picture=http%3A%2F%2F" + image + "&name=" + self.title +
"&redirect_uri=http%3A%2F%2F" + full_path
return link
def email_share_url(self):
settings.use_editable()
request = current_request()
host = request.get_host()
full_path = host + self.get_absolute_url()
site_title = '%s%s' % (settings.SITE_TITLE, ' Calendar')
link = "mailto:?subject=" + urllib.quote(site_title) + "%20-%20" +
self.title + "!&body=http%3A%2F%2F" + full_path
return link
Then in the templates there are things like:
{{ event.email_share_url }}
{{ event.facebook_share_url }}
Today I noticed that this is extremely inefficient, a page with 3 events
(each method was called 3 times, I checked to be sure that was the case) on
it used 547 SQL queries. Simply removing settings.use_editable() reduced
the page to 31 queries.
The 547 queries are mostly like:
*SELECT* ••• <http://127.0.0.1:8000/calendar/month/2014/09/#> *FROM*
"django_site" *WHERE* "django_site"."domain" *LIKE* '127.0.0.1:8000'
*ESCAPE* '\'
*SELECT* ••• <http://127.0.0.1:8000/calendar/month/2014/09/#> *FROM*
"conf_setting" *INNER JOIN* "conf_setting_sites" *ON* ("conf_setting"."id"
= "conf_setting_sites"."setting_id") *WHERE* "conf_setting_sites"."site_id"
= 1
Does anyone have any ideas about how to solve this without removing
use_editable()?
Thanks!
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.