DjangoBB

Django based forum engine

  • You are not logged in.
  • Root
  • » The Other
  • » Quick way of figuring out if there are unread messages [RSS Feed]

#1 July 28, 2011 21:19:44

BrianHV
Registered: 2011-07-28
Posts: 4
Reputation: +  0  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

I have a low-traffic forum as part of a larger django project. I want my base page to have an indicator showing if there are unread messages. Is there an easy way to do that? Bonus points for providing the number of unread messages.

On a related note, is there a reason for using the JSONField to track unread messages rather than using a tracking table?

Offline

#2 July 29, 2011 17:31:50

slav0nic
DjangoBB Developer
From: Ukraine
Registered: 2009-10-25
Posts: 382
Reputation: +  5  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

reason of course exist, or u have batter solution (excluded coma separated fields, etc)?
M2M?) it really sux, as u planing marked all readed topics etc + with m2m u got tons of entries, in django bb max len((entries in tracing tables) <= len(users)

but, it's not brilliant i planing rewrite part with marking read/unread for forum

what about first question - interesting question:
https://bitbucket.org/slav0nic/djangobb/changeset/ddfffe696aa8 [bitbucket.org] maybe this will help for understand as this work

u can show last posts and shown if its readed via has_unreads tag [bitbucket.org]

Edited slav0nic (July 29, 2011 17:32:58)

Offline

#3 July 29, 2011 18:34:20

BrianHV
Registered: 2011-07-28
Posts: 4
Reputation: +  0  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

I forgot to mention that I knew about has_unreads. I'm looking for a version of that that doesn't require a topic as an argument; I need to know if the user has any unread posts in the entire forum.

As for the unread tracking, I'd keep it simple:

    class PostsRead(models.Model):
user = models.ForeignKey(User)
post = models.ForeignKey(Post)

class Meta:
unique_together = ('user', 'post')
Doing it this way would allow for querying the unread posts directly without having to decode a JSON string first.

(Edit: playing around with formatting. Can't figure out how to get the code to indent.)

Edited again: think I figured out formatting. But I also think that may have been what you mean when you mentioned m2m fields. Did you already try this? Did you hit performance issues or something?

Edited BrianHV (July 29, 2011 18:49:25)

Offline

#4 Aug. 1, 2011 09:45:01

slav0nic
DjangoBB Developer
From: Ukraine
Registered: 2009-10-25
Posts: 382
Reputation: +  5  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

u used very old forum version maybe with trouble at deleting posts (then can droping topic / forum if u tried deleting last post/topic)

yes, m2m is slow and limited in some case.

for detecting is forum has unreaded posts u can check is last_posts at forum readed by user (exist at m2m), no? - forum unreaded

Offline

#5 Aug. 11, 2011 23:49:07

BrianHV
Registered: 2011-07-28
Posts: 4
Reputation: +  0  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

If anyone else needs this, here's the filter I wrote. Most of this code is cribbed from the search view in djangobb_forum/views.py. It's fast enough for my current needs, but no guarantees that it will scale.

from django import template
from django.db.models import Q
from djangobb_forum import settings as forum_settings
from djangobb_forum.models import PostTracking, Topic
from djangobb_forum.templatetags import forum_extras

register = template.Library()

@register.filter
def unread_topics(user):
groups = user.groups.all() or [] #removed after django > 1.2.3 release
topics = Topic.objects.filter(
Q(forum__category__groups__in=groups) | \
Q(forum__category__groups__isnull=True))
try:
last_read = PostTracking.objects.get(user=user).last_read
if last_read:
topics = topics.filter(last_post__updated__gte=last_read).all()
else:
#searching more than forum_settings.SEARCH_PAGE_SIZE in this way - not good idea :]
topics = [topic for topic in topics[:forum_settings.SEARCH_PAGE_SIZE] if forum_extras.has_unreads(topic, user)]
except PostTracking.DoesNotExist:
pass
return len(topics)

Edited BrianHV (Aug. 17, 2011 04:08:59)

Offline

#6 July 18, 2018 06:47:22

Danielnof
Registered: 2018-07-18
Posts: 4
Reputation: +  0  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

Offline

#7 July 18, 2018 06:47:23

CesarWhono
Registered: 2018-07-18
Posts: 4
Reputation: +  0  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

Offline

#8 July 18, 2018 06:49:04

DavidDab
Registered: 2018-07-18
Posts: 26
Reputation: +  0  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

Offline

#9 July 19, 2018 13:17:24

Briandom
Registered: 2018-07-18
Posts: 25
Reputation: +  0  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

Offline

#10 July 19, 2018 13:24:32

DavidDab
Registered: 2018-07-18
Posts: 26
Reputation: +  0  -
Profile   Send e-mail  

Quick way of figuring out if there are unread messages

Offline

  • Root
  • » The Other
  • » Quick way of figuring out if there are unread messages[RSS Feed]

Board footer

Moderator control

Powered by DjangoBB

Lo-Fi Version