Preperation for savig account data

This commit is contained in:
Mikhail Shabanov committed 2020-10-25 19:05:08 +01:00
1 parent 5e0369511f
commit 91f69a6e39
5 files changed
+75 -14

No files matched your search

@@ -1,5 +1,4 @@
using System.Runtime.Serialization.Formatters;
using MongoDB.Driver;
using MongoDB.Driver;
using WotBlitzStatisticsPro.Common;
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
@@ -8,6 +7,9 @@ namespace WotBlitzStatisticsPro.DataAccess
public class WargamingAccountDataAccessor : IWargamingAccountDataAccessor
{
private const string AccountInfoCollectionName = "account-info";
private const string AccountInfoHistoryCollectionName = "account-info-history";
private const string TankInfoCollectionName = "tank-info";
private const string TankInfoHistoryCollectionName = "tank-info-history";
private readonly IMongoDatabase _database;
@@ -22,23 +24,45 @@ namespace WotBlitzStatisticsPro.DataAccess
private void CreateAccountIndexesIfNotExists()
{
// Account Info
var accountInfoBuilder = Builders<AccountInfo>.IndexKeys;
var accountInfoRealmIndexModel = new CreateIndexModel<AccountInfo>(accountInfoBuilder.Ascending(a => a.Realm));
var accountInfoLastBattleTimeIndexModel = new CreateIndexModel<AccountInfo>(accountInfoBuilder.Descending(a => a.LastBattleTime));
_database.GetCollection<AccountInfo>(AccountInfoCollectionName).Indexes
.CreateMany(new[] {accountInfoRealmIndexModel, accountInfoLastBattleTimeIndexModel});
// AccountInfoHistory AccountId+LastBattleTime
var accountInfoHistoryBuilder = Builders<AccountInfoHistory>.IndexKeys;
var accountInfoHistoryIndexModel = new CreateIndexModel<AccountInfoHistory>(
accountInfoHistoryBuilder.Combine(
Builders<AccountInfoHistory>.IndexKeys.Ascending(h => h.AccountId),
Builders<AccountInfoHistory>.IndexKeys.Ascending(h => h.LastBattleTime)));
_database.GetCollection<AccountInfoHistory>(AccountInfoHistoryCollectionName).Indexes
.CreateOne(accountInfoHistoryIndexModel);
/*
// TankInfo AccountId+TankId, LastBattleTime
var tankInfoBuilder = Builders<TankInfo>.IndexKeys;
var tankInfoIndexModel = new CreateIndexModel<TankInfo>(
tankInfoBuilder.Combine(
Builders<TankInfo>.IndexKeys.Ascending(h => h.AccountId),
Builders<TankInfo>.IndexKeys.Ascending(h => h.TankId)));
var tankInfoLastBattleTimeIndexModel =
new CreateIndexModel<TankInfo>(tankInfoBuilder.Ascending(t => t.LastBattleTime));
_database.GetCollection<TankInfo>(TankInfoCollectionName).Indexes
.CreateMany(new[] {tankInfoIndexModel, tankInfoLastBattleTimeIndexModel});
// Multiple keys
var indexDefinition = Builders<FooDocument>.IndexKeys.Combine(
Builders<FooDocument>.IndexKeys.Ascending(f => f.Key1),
Builders<FooDocument>.IndexKeys.Ascending(f => f.Key2));
await collection.Indexes.CreateOneAsync(indexDefinition);
*/
// TankInfoHistory AccountId+TankId+LastBattleTime
var tankInfoHistoryBuilder = Builders<TankInfoHistory>.IndexKeys;
var tankInfoHistoryIndexModel = new CreateIndexModel<TankInfoHistory>(
tankInfoHistoryBuilder.Combine(
Builders<TankInfoHistory>.IndexKeys.Ascending(h => h.AccountId),
Builders<TankInfoHistory>.IndexKeys.Ascending(h => h.TankId),
Builders<TankInfoHistory>.IndexKeys.Ascending(h => h.LastBattleTime)));
_database.GetCollection<TankInfoHistory>(TankInfoHistoryCollectionName).Indexes
.CreateOne(tankInfoHistoryIndexModel);
}
// ToDo: Read account
}
}