🐛 Fix publisher subscription cache and status validation
This commit is contained in:
@ -9,7 +9,6 @@ namespace DysonNetwork.Sphere.Publisher;
|
||||
public class PublisherService(AppDatabase db, FileReferenceService fileRefService, ICacheService cache)
|
||||
{
|
||||
private const string UserPublishersCacheKey = "accounts:{0}:publishers";
|
||||
private const string UserPublishersBatchCacheKey = "accounts:batch:{0}:publishers";
|
||||
|
||||
public async Task<List<Publisher>> GetUserPublishers(Guid userId)
|
||||
{
|
||||
@ -89,7 +88,7 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
|
||||
|
||||
|
||||
private const string SubscribedPublishersCacheKey = "accounts:{0}:subscribed-publishers";
|
||||
public const string SubscribedPublishersCacheKey = "accounts:{0}:subscribed-publishers";
|
||||
|
||||
public async Task<List<Publisher>> GetSubscribedPublishers(Guid userId)
|
||||
{
|
||||
@ -103,6 +102,7 @@ public class PublisherService(AppDatabase db, FileReferenceService fileRefServic
|
||||
// If not in cache, fetch from a database
|
||||
var publishersId = await db.PublisherSubscriptions
|
||||
.Where(p => p.AccountId == userId)
|
||||
.Where(p => p.Status == SubscriptionStatus.Active)
|
||||
.Select(p => p.PublisherId)
|
||||
.ToListAsync();
|
||||
publishers = await db.Publishers
|
||||
|
@ -1,5 +1,6 @@
|
||||
using DysonNetwork.Sphere.Account;
|
||||
using DysonNetwork.Sphere.Post;
|
||||
using DysonNetwork.Sphere.Storage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
@ -9,7 +10,9 @@ public class PublisherSubscriptionService(
|
||||
AppDatabase db,
|
||||
NotificationService nty,
|
||||
PostService ps,
|
||||
IStringLocalizer<Notification> localizer)
|
||||
IStringLocalizer<Notification> localizer,
|
||||
ICacheService cache
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if a subscription exists between the account and publisher
|
||||
@ -158,6 +161,8 @@ public class PublisherSubscriptionService(
|
||||
|
||||
db.PublisherSubscriptions.Add(subscription);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await cache.RemoveAsync(string.Format(PublisherService.SubscribedPublishersCacheKey, accountId));
|
||||
|
||||
return subscription;
|
||||
}
|
||||
@ -176,6 +181,9 @@ public class PublisherSubscriptionService(
|
||||
|
||||
subscription.Status = SubscriptionStatus.Cancelled;
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await cache.RemoveAsync(string.Format(PublisherService.SubscribedPublishersCacheKey, accountId));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user