Sphene Community Tools

Community

Copyright © 2007-2018 by Herbert Poul

You are not logged in.
Login
Register

Change Language:



AddThis Social Bookmark Button

A Django site.

Powered by Sphene Community Tools
Board » General » Feature Discussions » Caching of user profile

Information about post author rendered by sphboard_extras.py->sphboard_post_authorinfo is cached. Because of that, after user writes new post, displayed number of posts is not accurate until cache expires.
For me, as a board user, this seems to be strange that after I've posted two new messages I still see 'Posts: 1'.

My proposal is to clean cache after new post has been created. Something like the code below might be added to sphboard/models.py. What do you think?

from django.db.models.signals import post_save
from django.core.cache import cache

from sphene.sphboard.templatetags.sphboard_extras import authorinfo_cachekey
from sphene.sphboard.models import Post

def clear_profile_cache_author(sender, instance, created, **kwargs):
    if instance.author and created:
        key = authorinfo_cachekey(user_id=instance.author.pk)
        cache.delete(key)
post_save.connect(clear_profile_cache_author, sender = Post)
hmm.. i actually don't understand why it isn't working ..

in models.py you have:
def update_post_count(instance, **kwargs):
    UserPostCount.objects.update_post_count( instance.author, instance.category.group )

signals.post_save.connect(update_post_count,
                   sender = Post)


and in templatetags/sphboard_extras.py:
signals.post_save.connect(clear_authorinfo_cache_postcount,
                   sender = UserPostCount)


i guess i have to debug this further. .have you experienced it in your local installation as well as on this site (sct.sphene.net)?
Hey, we have Signatures !!! Great, isn't it ? ;)
hmm.. i actually don't understand why it isn't working ..

in models.py you have:
def update_post_count(instance, **kwargs):
    UserPostCount.objects.update_post_count( instance.author, instance.category.group )

signals.post_save.connect(update_post_count,
                   sender = Post)


and in templatetags/sphboard_extras.py:
signals.post_save.connect(clear_authorinfo_cache_postcount,
                   sender = UserPostCount)


i guess i have to debug this further. .have you experienced it in your local installation as well as on this site (sct.sphene.net)?
This code updates UserPostCount.post_count, and it works properly, post_count is updated. The problem is that CACHE, used by sphboard_post_authorinfo (which displays profile information), is not invalidated at this moment, so user still sees old post count.
I've seen this behaviour both locally and at sct.sphene.net.
and in templatetags/sphboard_extras.py:
signals.post_save.connect(clear_authorinfo_cache_postcount,
                   sender = UserPostCount)

This code updates UserPostCount.post_count, and it works properly, post_count is updated. The problem is that CACHE, used by sphboard_post_authorinfo (which displays profile information), is not invalidated at this moment, so user still sees old post count.
I've seen this behaviour both locally and at sct.sphene.net.
yeah, but when updating UserPostCount the signal handler in templatetags/sphboard_extras.py should be called.. and clear_authorinfo_cache_postcount should actually clear the authorinfo cache for every language
Hey, we have Signatures !!! Great, isn't it ? ;)
yeah, but when updating UserPostCount the signal handler in templatetags/sphboard_extras.py should be called.. and clear_authorinfo_cache_postcount should actually clear the authorinfo cache for every language
Oh.. right, I didn't notice that.
Seems for me that the problem is in sphboard_extras.py->authorinfo_cachekey with LANGUAGE_CODE attribute:
language_code = getattr(get_current_request(), 'LANGUAGE_CODE', '')

request object stored in threads_local is not instance of RequestContext but instance of WSGIRequest so there is no LANGUAGE_CODE attribute.

Please login to post a reply.



Powered by Sphene Community Tools