Skip to content

Commit

Permalink
Cleaned up for loops. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamaalscarlett authored and safwanrahman committed May 9, 2016
1 parent f78c361 commit a5e0010
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions webpush/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@
def send_notification_to_user(user, payload, ttl=0):
# Get all the push_info of the user
push_infos = user.webpush_info.select_related("subscription")

numbers = range(push_infos.count())

for i in numbers:
push_info = push_infos[i]
for push_info in push_infos:
_send_notification(push_info, payload, ttl)


def send_notification_to_group(group_name, payload, ttl=0):

# Get all the subscription related to the group
push_infos = Group.objects.get(name=group_name).webpush_info.select_related("subscription")
# As there can be many subscription, iterating the large number will make it slow
# so count the number and cut according to it
numbers = range(push_infos.count())

for i in numbers:
push_info = push_infos[i]
for push_info in push_infos:
_send_notification(push_info, payload, ttl)


Expand Down

0 comments on commit a5e0010

Please sign in to comment.