﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14195	ContentType object fails to use cache, beats DB to death	Mark Jones	nobody	"using the content_type.model member causes a DB SELECT instead of using the cache of ContentTypes

This is the partial class definition 
{{{
#!python
class Activity(models.Model):
    action_time = models.DateTimeField(_('action time'), auto_now=True)
    user = models.ForeignKey(User, related_name='activities')
    content_type = models.ForeignKey(ContentType, blank=True, null=True)
    ...

    def short_template(self):
        ""Returns the name of the short template to display this item""
        return ""activity/short/"" + self.content_type.model + "".html""
}}}

this is the select statement

{{{
#!python
    activities = Activity.objects.filter(user=user).select_related('user')[:25]

    for act in activities:
        print act.short_template()
}}}

The above code will hit the DB once for every Activity object where you do self.content.model, in spite of the comments in the code about a cache, and the presence of the cache in the code.  Seems like the content_type should be built from the cache when the object is fetched, or at least fetched from the cache instead of the database."	Uncategorized	closed	Uncategorized	1.2	Normal	duplicate		German M. Bravo	Someday/Maybe	0	0	0	0	0	0
