restricts the number of users in the online section

This commit is contained in:
Nathan Dinsmore 2013-02-11 17:24:57 -05:00
parent 8c36beaeb7
commit 4102a0c42f
3 changed files with 9 additions and 1 deletions

View file

@ -37,6 +37,7 @@ POST_FLOOD = get('DJANGOBB_POST_FLOOD', False) # wait time between posts for cer
POST_FLOOD_SLOW = get('DJANGOBB_POST_FLOOD_SLOW', False)
POST_FLOOD_MED = get('DJANGOBB_POST_FLOOD_MED', False)
TOPIC_CLOSE_DELAY = get('DJANGOBB_TOPIC_CLOSE_DELAY', 0)
MAX_ONLINE = get('DJANGOBB_MAX_ONLINE', 20)
# GRAVATAR Extension
GRAVATAR_SUPPORT = get('DJANGOBB_GRAVATAR_SUPPORT', True)

View file

@ -90,5 +90,8 @@
{% for online in users_online %}
<dd>{{ online|profile_link }}{% if not forloop.last %},{% endif %}</dd>
{% endfor %}
{% if online_truncated %}
<dd>{% trans "…and more." %}</dd>
{% endif %}
</dl>
{% endblock %}

View file

@ -38,10 +38,13 @@ from djangobb_forum.util import build_form, paginate, set_language, smiles, conv
def index(request, full=True):
users_cached = cache.get('djangobb_users_online', {})
users_online = users_cached and User.objects.filter(id__in=users_cached.keys()) or []
users_online = users_cached and User.objects.filter(id__in=users_cached.keys())[:forum_settings.MAX_ONLINE + 1] or []
guests_cached = cache.get('djangobb_guests_online', {})
guest_count = len(guests_cached)
users_count = len(users_online)
online_truncated = users_count > forum_settings.MAX_ONLINE
if online_truncated:
users_online = users_online[:-1]
_forums = Forum.objects.all()
user = request.user
@ -68,6 +71,7 @@ def index(request, full=True):
'users': User.objects.count(),
'users_online': users_online,
'online_count': users_count,
'online_truncated': online_truncated,
'guest_count': guest_count,
'last_user': User.objects.latest('date_joined')
}