public async Task <IPage <Model> > Handle(Query request, CancellationToken cancellationToken) { CirculatingSupply supply = await _statsCache.GetAsync <CirculatingSupply>(CirculatingSupply.DefaultCacheKey, null) .AnyContext(); IPage <CinderAddress> page = await _addressRepository.GetRichest(request.Page, request.Size, _settings.Performance.RichListMinimumBalance, _settings.Performance.QueryCountLimiter, cancellationToken) .AnyContext(); IEnumerable <CinderAddressMeta> metas = await _addressMetaRepository .GetByAddresses(page.Items.Select(address => address.Hash).Distinct(), cancellationToken) .AnyContext(); decimal circulatingSupply = supply?.Supply ?? 0; int rank = 1 * (page.Page - 1) * page.Size + 1; IEnumerable <Model> models = page.Items.Select(address => { CinderAddressMeta meta = metas.FirstOrDefault(x => x.Id == address.Id); return(new Model { Rank = rank++, Name = meta?.Name, Hash = address.Hash, Balance = address.Balance, Percent = address.Balance > 0 && circulatingSupply > 0 ? address.Balance / circulatingSupply * 100 : default,
public async Task <Model> Handle(Query request, CancellationToken cancellationToken) { CirculatingSupply supply = await _statsCache.GetAsync(CirculatingSupply.DefaultCacheKey, new CirculatingSupply()) .AnyContext(); return(new Model { Supply = supply.Supply }); }
protected override async Task <JobResult> RunInternalAsync(JobContext context) { try { CirculatingSupply supply = await _statsCache.GetAsync(CirculatingSupply.DefaultCacheKey, new CirculatingSupply()) .AnyContext(); supply.Supply = await _addressRepository.GetSupply().AnyContext(); await _statsCache.SetAsync(CirculatingSupply.DefaultCacheKey, supply).AnyContext(); } catch (Exception e) { return(JobResult.FromException(e)); } return(JobResult.Success); }