sync: remove item type specific model classes & simplify sync repository usage

This commit is contained in:
Abdullah Atta
2024-06-07 11:10:43 +05:00
parent 90b9012c32
commit ad4e43e879
6 changed files with 113 additions and 152 deletions

View File

@@ -37,15 +37,19 @@ using Streetwriters.Data.Repositories;
namespace Notesnook.API.Repositories
{
public class SyncItemsRepository<T> : Repository<SyncItem> where T : SyncItem
public class SyncItemsRepository : Repository<SyncItem>
{
private string collectionName;
public SyncItemsRepository(IDbContext dbContext, string databaseName, string collectionName) : base(dbContext, databaseName, collectionName)
private readonly string collectionName;
public SyncItemsRepository(IDbContext dbContext, IMongoCollection<SyncItem> collection) : base(dbContext, collection)
{
this.collectionName = collectionName;
Collection.Indexes.CreateOne(new CreateIndexModel<SyncItem>(Builders<SyncItem>.IndexKeys.Ascending(i => i.UserId).Descending(i => i.DateSynced)));
Collection.Indexes.CreateOne(new CreateIndexModel<SyncItem>(Builders<SyncItem>.IndexKeys.Ascending(i => i.UserId).Ascending((i) => i.ItemId)));
Collection.Indexes.CreateOne(new CreateIndexModel<SyncItem>(Builders<SyncItem>.IndexKeys.Ascending(i => i.UserId)));
this.collectionName = collection.CollectionNamespace.CollectionName;
#if DEBUG
Collection.Indexes.CreateMany([
new CreateIndexModel<SyncItem>(Builders<SyncItem>.IndexKeys.Ascending("UserId").Descending("DateSynced")),
new CreateIndexModel<SyncItem>(Builders<SyncItem>.IndexKeys.Ascending("UserId").Ascending("ItemId")),
new CreateIndexModel<SyncItem>(Builders<SyncItem>.IndexKeys.Ascending("UserId"))
]);
#endif
}
private readonly List<string> ALGORITHMS = new List<string> { Algorithms.Default };