Skip to content

Commit

Permalink
refactor: remove cache
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 committed Jul 18, 2024
1 parent 5315b0b commit e10cd67
Showing 1 changed file with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ public class WebsiteMessageQueryHandler
private readonly IMcQueryContext _context;
private readonly IUserContext _userContext;
private readonly II18n<DefaultResource> _i18n;
private IMultilevelCacheClient _cache;

public WebsiteMessageQueryHandler(IMcQueryContext context
, IUserContext userContext
, II18n<DefaultResource> i18n
, IMultilevelCacheClient cache)
, II18n<DefaultResource> i18n)
{
_context = context;
_userContext = userContext;
_i18n = i18n;
_cache = cache;
}

[EventHandler]
Expand Down Expand Up @@ -80,15 +77,6 @@ public async Task GetChannelListAsync(GetChannelListWebsiteMessageQuery query)
public async Task GetNoticeListAsync(GetNoticeListQuery query)
{
var userId = _userContext.GetUserId<Guid>();
var cacheKey = CacheKeys.GET_NOTICE_LIST + "-" + userId;

var response = _cache.Get<List<WebsiteMessageDto>>(cacheKey);
if (response != null)
{
query.Result = response;
return;
}

var noticeNum = query.PageSize;
var queryable = _context.WebsiteMessageQueries.Include(x => x.Channel).Where(x => x.Channel != null && x.UserId == userId && !x.IsWithdrawn);
var list = await queryable.Where(x => !x.IsRead).OrderByDescending(x => x.CreationTime).Take(noticeNum).ToListAsync();
Expand All @@ -101,11 +89,6 @@ public async Task GetNoticeListAsync(GetNoticeListQuery query)
var dtos = list.Adapt<List<WebsiteMessageDto>>();
FillListDtos(dtos);

if (dtos.Any())
{
_cache.Set(cacheKey, dtos ?? new(), DateTimeOffset.Now.AddMinutes(10));
}

query.Result = dtos ?? new();
}

Expand Down

0 comments on commit e10cd67

Please sign in to comment.