Posted by pigletto |
|
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) |
|
Posted by Herbert Poul |
|
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 ? ;) |
|
Posted by pigletto |
|
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. |
|
Posted by Herbert Poul |
|
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 ? ;) |
|
Posted by pigletto |
|
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.