♻️ Moving to MagicOnion
This commit is contained in:
		| @@ -1,13 +1,13 @@ | ||||
| using DysonNetwork.Shared.Cache; | ||||
| using DysonNetwork.Shared.Models; | ||||
| using DysonNetwork.Shared.Services; | ||||
| using MagicOnion.Server; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using NodaTime; | ||||
|  | ||||
| namespace DysonNetwork.Pass.Account; | ||||
|  | ||||
| public class RelationshipService( | ||||
|     AppDatabase db | ||||
|     // ICacheService cache | ||||
| ) | ||||
| public class RelationshipService(AppDatabase db, ICacheService cache) : ServiceBase<IRelationshipService>, IRelationshipService | ||||
| { | ||||
|     private const string UserFriendsCacheKeyPrefix = "accounts:friends:"; | ||||
|     private const string UserBlockedCacheKeyPrefix = "accounts:blocked:"; | ||||
| @@ -150,7 +150,7 @@ public class RelationshipService( | ||||
|         db.Update(relationship); | ||||
|         await db.SaveChangesAsync(); | ||||
|          | ||||
|         // await PurgeRelationshipCache(accountId, relatedId); | ||||
|         await PurgeRelationshipCache(accountId, relatedId); | ||||
|          | ||||
|         return relationship; | ||||
|     } | ||||
| @@ -158,8 +158,7 @@ public class RelationshipService( | ||||
|     public async Task<List<Guid>> ListAccountFriends(Shared.Models.Account account) | ||||
|     { | ||||
|         var cacheKey = $"{UserFriendsCacheKeyPrefix}{account.Id}"; | ||||
|         // var friends = await cache.GetAsync<List<Guid>>(cacheKey); | ||||
|         var friends = new List<Guid>(); // Placeholder | ||||
|         var friends = await cache.GetAsync<List<Guid>>(cacheKey); | ||||
|          | ||||
|         if (friends == null) | ||||
|         { | ||||
| @@ -169,17 +168,16 @@ public class RelationshipService( | ||||
|                 .Select(r => r.AccountId) | ||||
|                 .ToListAsync(); | ||||
|                  | ||||
|             // await cache.SetAsync(cacheKey, friends, TimeSpan.FromHours(1)); | ||||
|             await cache.SetAsync(cacheKey, friends, TimeSpan.FromHours(1)); | ||||
|         } | ||||
|  | ||||
|         return friends ?? []; | ||||
|         return friends; | ||||
|     } | ||||
|      | ||||
|     public async Task<List<Guid>> ListAccountBlocked(Shared.Models.Account account) | ||||
|     { | ||||
|         var cacheKey = $"{UserBlockedCacheKeyPrefix}{account.Id}"; | ||||
|         // var blocked = await cache.GetAsync<List<Guid>>(cacheKey); | ||||
|         var blocked = new List<Guid>(); // Placeholder | ||||
|         var blocked = await cache.GetAsync<List<Guid>>(cacheKey); | ||||
|          | ||||
|         if (blocked == null) | ||||
|         { | ||||
| @@ -189,10 +187,10 @@ public class RelationshipService( | ||||
|                 .Select(r => r.AccountId) | ||||
|                 .ToListAsync(); | ||||
|                  | ||||
|             // await cache.SetAsync(cacheKey, blocked, TimeSpan.FromHours(1)); | ||||
|             await cache.SetAsync(cacheKey, blocked, TimeSpan.FromHours(1)); | ||||
|         } | ||||
|  | ||||
|         return blocked ?? []; | ||||
|         return blocked; | ||||
|     } | ||||
|  | ||||
|     public async Task<bool> HasRelationshipWithStatus(Guid accountId, Guid relatedId, | ||||
| @@ -204,9 +202,9 @@ public class RelationshipService( | ||||
|      | ||||
|     private async Task PurgeRelationshipCache(Guid accountId, Guid relatedId) | ||||
|     { | ||||
|         // await cache.RemoveAsync($"{UserFriendsCacheKeyPrefix}{accountId}"); | ||||
|         // await cache.RemoveAsync($"{UserFriendsCacheKeyPrefix}{relatedId}"); | ||||
|         // await cache.RemoveAsync($"{UserBlockedCacheKeyPrefix}{accountId}"); | ||||
|         // await cache.RemoveAsync($"{UserBlockedCacheKeyPrefix}{relatedId}"); | ||||
|         await cache.RemoveAsync($"{UserFriendsCacheKeyPrefix}{accountId}"); | ||||
|         await cache.RemoveAsync($"{UserFriendsCacheKeyPrefix}{relatedId}"); | ||||
|         await cache.RemoveAsync($"{UserBlockedCacheKeyPrefix}{accountId}"); | ||||
|         await cache.RemoveAsync($"{UserBlockedCacheKeyPrefix}{relatedId}"); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user