diff --git a/OpenAlprWebhookProcessor/WebhookProcessor/GroupWebhookHandler.cs b/OpenAlprWebhookProcessor/WebhookProcessor/GroupWebhookHandler.cs index c3a5d60e..0e1c513e 100644 --- a/OpenAlprWebhookProcessor/WebhookProcessor/GroupWebhookHandler.cs +++ b/OpenAlprWebhookProcessor/WebhookProcessor/GroupWebhookHandler.cs @@ -43,7 +43,6 @@ public GroupWebhookHandler( public async Task HandleWebhookAsync( Webhook webhook, bool isBulkImport, - List previouslyProcessedGroups, CancellationToken cancellationToken) { var camera = await _processorContext.Cameras @@ -68,41 +67,18 @@ public async Task HandleWebhookAsync( return; } - var alreadyProcessed = false; - - if (previouslyProcessedGroups != null) - { - alreadyProcessed = previouslyProcessedGroups - .Intersect(webhook.Group.Uuids) - .Any(); - - if (!alreadyProcessed) - { - previouslyProcessedGroups.AddRange(webhook.Group.Uuids); - } - } - else - { - alreadyProcessed = await _processorContext.PlateGroups.Select(x => x.OpenAlprUuid) - .Intersect(webhook.Group.Uuids) - .AnyAsync(cancellationToken); - } - - if (alreadyProcessed) - { - _logger.LogWarning("Duplicate group received, skipping: " + webhook.Group.BestUuid); - return; - } - - var previousPreviewGroup = await _processorContext.PlateGroups + var previousPreviewGroups = await _processorContext.PlateGroups .Where(x => webhook.Group.Uuids.Contains(x.OpenAlprUuid)) - .FirstOrDefaultAsync(cancellationToken); + .ToListAsync(cancellationToken); PlateGroup plateGroup; - if (previousPreviewGroup != null) + if (previousPreviewGroups.Count > 0) { - _logger.LogInformation("Previous preview plate exists: " + previousPreviewGroup.BestNumber + ", overwriting"); - plateGroup = previousPreviewGroup; + plateGroup = previousPreviewGroups[0]; + _processorContext.PlateGroups.RemoveRange(previousPreviewGroups.Skip(1)); + + _logger.LogInformation("Previous preview plate exists: " + plateGroup.BestNumber + ", overwriting"); + } else { @@ -124,7 +100,7 @@ public async Task HandleWebhookAsync( MapVehicle(plateGroup, webhook); - if (previousPreviewGroup == null) + if (previousPreviewGroups.Count == 0) { _processorContext.PlateGroups.Add(plateGroup); } diff --git a/OpenAlprWebhookProcessor/WebhookProcessor/OpenAlprAgentScraper/OpenAlprAgentScraper.cs b/OpenAlprWebhookProcessor/WebhookProcessor/OpenAlprAgentScraper/OpenAlprAgentScraper.cs index 5c94036b..500bd940 100644 --- a/OpenAlprWebhookProcessor/WebhookProcessor/OpenAlprAgentScraper/OpenAlprAgentScraper.cs +++ b/OpenAlprWebhookProcessor/WebhookProcessor/OpenAlprAgentScraper/OpenAlprAgentScraper.cs @@ -93,9 +93,6 @@ await newGroup.Content.ReadAsStreamAsync(cancellationToken), continue; } - var previouslyProcessedGroups = await _processorContext.PlateGroups - .Select(x => x.OpenAlprUuid) - .ToListAsync(cancellationToken); try { await _groupWebhookHandler.HandleWebhookAsync( @@ -104,7 +101,6 @@ await _groupWebhookHandler.HandleWebhookAsync( Group = group, }, true, - previouslyProcessedGroups, cancellationToken); } catch diff --git a/OpenAlprWebhookProcessor/WebhookProcessor/WebhookController.cs b/OpenAlprWebhookProcessor/WebhookProcessor/WebhookController.cs index 09a48b31..b09f2e36 100644 --- a/OpenAlprWebhookProcessor/WebhookProcessor/WebhookController.cs +++ b/OpenAlprWebhookProcessor/WebhookProcessor/WebhookController.cs @@ -48,7 +48,6 @@ public async Task Post(CancellationToken cancellationToken) await _groupWebhookHandler.HandleWebhookAsync( alertGroupResult, false, - null, cancellationToken); } else if (rawWebhook.Contains("alpr_group")) @@ -62,7 +61,6 @@ await _groupWebhookHandler.HandleWebhookAsync( await _groupWebhookHandler.HandleWebhookAsync( groupResult, false, - null, cancellationToken); } else if (rawWebhook.Contains("alpr_results"))