🐛 Fix subscription notification send twice
This commit is contained in:
parent
a5dae37525
commit
ec3961d546
@ -216,13 +216,6 @@ public class PostController(
|
|||||||
return BadRequest(err.Message);
|
return BadRequest(err.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
using var scope = factory.CreateScope();
|
|
||||||
var subs = scope.ServiceProvider.GetRequiredService<PublisherSubscriptionService>();
|
|
||||||
await subs.NotifySubscriberPost(post);
|
|
||||||
});
|
|
||||||
|
|
||||||
als.CreateActionLogFromRequest(
|
als.CreateActionLogFromRequest(
|
||||||
ActionLogType.PostCreate,
|
ActionLogType.PostCreate,
|
||||||
new Dictionary<string, object> { { "post_id", post.Id } }, Request
|
new Dictionary<string, object> { { "post_id", post.Id } }, Request
|
||||||
|
@ -52,7 +52,7 @@ public class PublisherSubscriptionService(
|
|||||||
var subscribers = await db.PublisherSubscriptions
|
var subscribers = await db.PublisherSubscriptions
|
||||||
.Include(p => p.Account)
|
.Include(p => p.Account)
|
||||||
.Where(p => p.PublisherId == post.PublisherId &&
|
.Where(p => p.PublisherId == post.PublisherId &&
|
||||||
p.Status == PublisherSubscriptionStatus.Active)
|
p.Status == PublisherSubscriptionStatus.Active)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
if (subscribers.Count == 0)
|
if (subscribers.Count == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -69,7 +69,7 @@ public class PublisherSubscriptionService(
|
|||||||
|
|
||||||
// Notify each subscriber
|
// Notify each subscriber
|
||||||
var notifiedCount = 0;
|
var notifiedCount = 0;
|
||||||
foreach (var subscription in subscribers.GroupBy(s => s.AccountId).Select(g => g.First()))
|
foreach (var subscription in subscribers.DistinctBy(s => s.AccountId))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -162,7 +162,7 @@ public class PublisherSubscriptionService(
|
|||||||
|
|
||||||
db.PublisherSubscriptions.Add(subscription);
|
db.PublisherSubscriptions.Add(subscription);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
await cache.RemoveAsync(string.Format(PublisherService.SubscribedPublishersCacheKey, accountId));
|
await cache.RemoveAsync(string.Format(PublisherService.SubscribedPublishersCacheKey, accountId));
|
||||||
|
|
||||||
return subscription;
|
return subscription;
|
||||||
@ -182,9 +182,9 @@ public class PublisherSubscriptionService(
|
|||||||
|
|
||||||
subscription.Status = PublisherSubscriptionStatus.Cancelled;
|
subscription.Status = PublisherSubscriptionStatus.Cancelled;
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
await cache.RemoveAsync(string.Format(PublisherService.SubscribedPublishersCacheKey, accountId));
|
await cache.RemoveAsync(string.Format(PublisherService.SubscribedPublishersCacheKey, accountId));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user