Avoid empty notifications when no effective modifications (#1074)

Fix TG-5341
remotes/origin/3.4.0rc 3.1.2
Miguel Gonzalez 2018-02-21 06:59:26 +01:00
parent d3a754997b
commit b05da06ab2
2 changed files with 12 additions and 6 deletions

View File

@ -245,14 +245,20 @@ def send_sync_notifications(notification_id):
""" """
notification = HistoryChangeNotification.objects.select_for_update().get(pk=notification_id) notification = HistoryChangeNotification.objects.select_for_update().get(pk=notification_id)
# If the last modification is too recent we ignore it # If the last modification is too recent we ignore it for the time being
now = timezone.now() now = timezone.now()
time_diff = now - notification.updated_datetime time_diff = now - notification.updated_datetime
if time_diff.seconds < settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL: if time_diff.seconds < settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL:
return return
history_entries = tuple(notification.history_entries.all().order_by("created_at")) history_entries = tuple(notification.history_entries.all().order_by("created_at"))
history_entries = squash_history_entries(history_entries) history_entries = list(squash_history_entries(history_entries))
# If there are no effective modifications we can delete this notification
# without further processing
if notification.history_type == HistoryType.change and not history_entries:
notification.delete()
return
obj, _ = get_last_snapshot_for_key(notification.key) obj, _ = get_last_snapshot_for_key(notification.key)
obj_class = get_model_from_key(obj.key) obj_class = get_model_from_key(obj.key)

View File

@ -359,7 +359,7 @@ def test_send_notifications_using_services_method_for_user_stories(settings, mai
history_change = f.HistoryEntryFactory.create( history_change = f.HistoryEntryFactory.create(
project=project, project=project,
user={"pk": member1.user.id}, user={"pk": member1.user.id},
comment="", comment="test:change",
type=HistoryType.change, type=HistoryType.change,
key="userstories.userstory:{}".format(us.id), key="userstories.userstory:{}".format(us.id),
is_hidden=False, is_hidden=False,
@ -454,7 +454,7 @@ def test_send_notifications_using_services_method_for_tasks(settings, mail):
history_change = f.HistoryEntryFactory.create( history_change = f.HistoryEntryFactory.create(
project=project, project=project,
user={"pk": member1.user.id}, user={"pk": member1.user.id},
comment="", comment="test:change",
type=HistoryType.change, type=HistoryType.change,
key="tasks.task:{}".format(task.id), key="tasks.task:{}".format(task.id),
is_hidden=False, is_hidden=False,
@ -549,7 +549,7 @@ def test_send_notifications_using_services_method_for_issues(settings, mail):
history_change = f.HistoryEntryFactory.create( history_change = f.HistoryEntryFactory.create(
project=project, project=project,
user={"pk": member1.user.id}, user={"pk": member1.user.id},
comment="", comment="test:change",
type=HistoryType.change, type=HistoryType.change,
key="issues.issue:{}".format(issue.id), key="issues.issue:{}".format(issue.id),
is_hidden=False, is_hidden=False,
@ -644,7 +644,7 @@ def test_send_notifications_using_services_method_for_wiki_pages(settings, mail)
history_change = f.HistoryEntryFactory.create( history_change = f.HistoryEntryFactory.create(
project=project, project=project,
user={"pk": member1.user.id}, user={"pk": member1.user.id},
comment="", comment="test:change",
type=HistoryType.change, type=HistoryType.change,
key="wiki.wikipage:{}".format(wiki.id), key="wiki.wikipage:{}".format(wiki.id),
is_hidden=False, is_hidden=False,