0

I'm using django notifications, but when unread notifications increasing, loading time and duplication times are also increasing. How can I optimize this code ?

            {% for notification in request.user.notifications.unread %}
            <li><div class="media">
                    <div class="media-left">
                      <div class="media-object">
                        <img data-src="holder.js/50x50?bg=cccccc" class="img-circle" alt="50x50" style="width: 50px; height: 50px;" 
                        src="{{ BASE_DIR}}/media/profile_pictures/{{notification|getNotifUser}}/profile.jpg" data-holder-rendered="true">
                      </div>
                    </div>
                    <div class="media-body">
                      <strong class="notification-title">
                        <a id="{{ notification.target_object_id }}" class="{{ notification.pk }}">
                          {{ notification.actor_object_id|get_username}}&nbsp;{{notification.verb}} - request {{notification.target_object_id}}</a></strong>
                      <div class="notification-meta">
                        <small class="timestamp">{{ notification.timesince | getLocalTimeDifference}} əvvəl</small>
                      </div>
                    </div>
            </div> </li>
            {% endfor %} 
Natiq Vahabov
  • 495
  • 4
  • 13
  • what the output of `{{ request.user.notifications.unread }}`? it is queryset? if yes, I think you can using `{{ request.user.notifications.unread.distinct }}` – binpy Feb 28 '17 at 06:11
  • same result and yes it is queryset – Natiq Vahabov Feb 28 '17 at 06:16
  • 1
    when I checked at the [source](https://github.com/django-notifications/django-notifications/blob/master/notifications/models.py#L49-L57), this function only filtered by `unread=True`, also `deleted=False`... perhaps you need more specific filter to do this... – binpy Feb 28 '17 at 06:19
  • you can check using `{{ notification.id }}` in your template, to makesure the objects isn't duplicates... if their `id/pk` from each objects is different, I think your problem is when you save the notification object.. – binpy Feb 28 '17 at 06:22

0 Answers0