From 7ccb7feeb4a470c00fbb1a3e9029e81fd30aad1d Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 17 Jul 2020 16:48:12 +0000 Subject: [PATCH] --- server/AyaNova/biz/NotifyEventProcessor.cs | 69 ++++++++++++---------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/server/AyaNova/biz/NotifyEventProcessor.cs b/server/AyaNova/biz/NotifyEventProcessor.cs index de7cb44a..7b4f110d 100644 --- a/server/AyaNova/biz/NotifyEventProcessor.cs +++ b/server/AyaNova/biz/NotifyEventProcessor.cs @@ -115,6 +115,8 @@ namespace AyaNova.Biz log.LogTrace($"HandlePotentialNotificationEvent processing: [AyaType:{newObject.AyaType}, AyaEvent:{ayaEvent}]"); + //set to true if any changes are made to the context (NotifyEvent added) + bool SaveContext = false; try { @@ -142,16 +144,16 @@ namespace AyaNova.Biz foreach (var sub in subs) { //todo: match tags if necessary - if (sub.Tags.Count > 0) + if (TagsMatch(newObject.Tags, sub.Tags)) { - if (!sub.Tags.All(z => newObject.Tags.Any(x => x == z))) - continue; + NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectCreated, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, SubscriptionId = sub.Id }; + await ct.NotifyEvent.AddAsync(n); + SaveContext = true; } - NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectCreated, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, SubscriptionId = sub.Id }; - await ct.NotifyEvent.AddAsync(n); + } - if (subs.Count > 0) - await ct.SaveChangesAsync(); + + } break; case AyaEvent.Modified: @@ -176,6 +178,28 @@ namespace AyaNova.Biz + if (SaveContext) + await ct.SaveChangesAsync(); + + + } + } + catch (Exception ex) + { + log.LogError(ex, $"Error processing event"); + } + finally + { + log.LogTrace($"Notify event processing completed"); + + } + + + }//eom + + + + //################### FIRST ATTEMPT STUFF // //find all the Notification subscription subs that are relevant // //this first query ensures that the equality matching conditions of AyaType and EventType and idValue are matched leaving only more complex matches to rectify below @@ -259,36 +283,19 @@ namespace AyaNova.Biz // } - - } - } - catch (Exception ex) - { - log.LogError(ex, $"Error processing event"); - } - finally - { - log.LogTrace($"Notify event processing completed"); - - } - - - }//eom - - - private static bool TagsMatch(List objectTags, List subTags){ + private static bool TagsMatch(List objectTags, List subTags) + { //no subscription tags? Then it always will match - if(subTags.Count==0) return true; + if (subTags.Count == 0) return true; //have sub tags but object has none? Then it's never going to match - if(objectTags.Count==0) return false; + if (objectTags.Count == 0) return false; //not enought tags on object to match sub tags? - if(subTags.Count > objectTags.Count) return false; + if (subTags.Count > objectTags.Count) return false; //ok, here it's worth checking it out -if (!sub.Tags.All(z => newObject.Tags.Any(x => x == z))) - continue; - + return subTags.All(z => objectTags.Any(x => x == z)); + } }//eoc