public async Task <SnapshotEntity> GetSnapshot(GetSnapshotRequest request)
        {
            var snapshotNoSql = _snapshotReader.Get(SnapshotNoSqlEntity.GeneratePartitionKey(request.WalletId),
                                                    SnapshotNoSqlEntity.GenerateRowKey(request.AssetId));

            if (snapshotNoSql.Entity != null)
            {
                return(snapshotNoSql.Entity);
            }

            var snapshot = await _snapshotGrpcService.GetSnapshot(request);

            return(snapshot);
        }
        public async Task <SnapshotListResponse> GetSnapshots(GetSnapshotsRequest request)
        {
            var snapshotNoSql = _snapshotReader.Get(SnapshotNoSqlEntity.GeneratePartitionKey(request.WalletId));

            if (snapshotNoSql.Any())
            {
                return new SnapshotListResponse()
                       {
                           Snapshots = snapshotNoSql.Select(t => t.Entity).ToList()
                       }
            }
            ;

            var snapshot = await _snapshotGrpcService.GetSnapshots(request);

            return(snapshot);
        }
    }
Ejemplo n.º 3
0
        public async Task <List <SnapshotEntity> > GetSnapshotsByWallet(string walletId)
        {
            var snapshotNoSqlEntities = (await _writer.GetAsync(SnapshotNoSqlEntity.GeneratePartitionKey(walletId))).ToList();

            if (snapshotNoSqlEntities.Any())
            {
                return(snapshotNoSqlEntities.Select(t => t.Entity).ToList());
            }

            await using var ctx = DatabaseContext.Create(_dbContextOptionsBuilder);
            var snapshotEntities = ctx.AvgSnapshots.Where(t => t.WalletId == walletId).ToList();

            if (snapshotEntities.Any())
            {
                await _writer.BulkInsertOrReplaceAsync(snapshotEntities.Select(SnapshotNoSqlEntity.Create));

                await _writer.CleanAndKeepMaxPartitions(Program.Settings.MaxCachedSnapshots);
            }

            return(snapshotEntities);
        }
Ejemplo n.º 4
0
        public async Task <SnapshotEntity> GetSnapshot(string walletId, string assetId)
        {
            var snapshot = await _writer.GetAsync(SnapshotNoSqlEntity.GeneratePartitionKey(walletId),
                                                  SnapshotNoSqlEntity.GenerateRowKey(assetId));

            if (snapshot != null)
            {
                return(snapshot.Entity);
            }

            await using var ctx = DatabaseContext.Create(_dbContextOptionsBuilder);
            var snapshotEntity = await ctx.AvgSnapshots.FirstOrDefaultAsync(t => t.AssetId == assetId && t.WalletId == walletId);

            if (snapshotEntity != null)
            {
                await _writer.InsertOrReplaceAsync(SnapshotNoSqlEntity.Create(snapshotEntity));

                await _writer.CleanAndKeepMaxPartitions(Program.Settings.MaxCachedSnapshots);
            }

            return(snapshotEntity);
        }