From b4e8b4938da90a486206d931e5ad3301be489adc Mon Sep 17 00:00:00 2001 From: TheDude Date: Thu, 25 Apr 2024 23:21:35 +0100 Subject: [PATCH] Fixed issue with timing out queries on mongo db (#210) --- .../Storage/Mongo/AngorMongoBuilder.cs | 4 ++++ .../SyncTasks/ProjectTransactionsSyncRunner.cs | 14 ++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Blockcore.Indexer.Angor/Storage/Mongo/AngorMongoBuilder.cs b/src/Blockcore.Indexer.Angor/Storage/Mongo/AngorMongoBuilder.cs index a4c03a9..2e06726 100644 --- a/src/Blockcore.Indexer.Angor/Storage/Mongo/AngorMongoBuilder.cs +++ b/src/Blockcore.Indexer.Angor/Storage/Mongo/AngorMongoBuilder.cs @@ -48,6 +48,10 @@ public override Task OnExecute() .CreateOne(new CreateIndexModel(Builders .IndexKeys.Descending(x => x.BlockIndex))); + AngorMongoDb.ProjectTable.Indexes + .CreateOne(new CreateIndexModel(Builders + .IndexKeys.Ascending(x => x.AddressOnFeeOutput))); + //TODO move this to the block indexer task runner, but we'll need to move the indexes in there to a different class for each project/blockchain AngorMongoDb.InvestmentTable.Indexes .CreateOne(new CreateIndexModel(Builders diff --git a/src/Blockcore.Indexer.Angor/Sync/SyncTasks/ProjectTransactionsSyncRunner.cs b/src/Blockcore.Indexer.Angor/Sync/SyncTasks/ProjectTransactionsSyncRunner.cs index 2252d73..68f8233 100644 --- a/src/Blockcore.Indexer.Angor/Sync/SyncTasks/ProjectTransactionsSyncRunner.cs +++ b/src/Blockcore.Indexer.Angor/Sync/SyncTasks/ProjectTransactionsSyncRunner.cs @@ -184,7 +184,6 @@ private BsonDocument[] MongoDbLookupForInvestments() new BsonDocument { { "address", "$AddressOnFeeOutput" }, - { "trx", "$TransactionId" }, { "projectMaxBlockScanned", "$projectMaxBlockScanned" } } }, @@ -197,13 +196,12 @@ private BsonDocument[] MongoDbLookupForInvestments() new BsonArray { "$Address", "$$address" }))), new BsonDocument("$match", new BsonDocument("$expr", - new BsonDocument("$and", new BsonArray - { - new BsonDocument("$gt", - new BsonArray { "$BlockIndex", "$$projectMaxBlockScanned" }), - new BsonDocument("$ne", - new BsonArray { "$$trx", "$Outpoint.TransactionId" }) - }))) + new BsonDocument("$gt", + new BsonArray { "$BlockIndex", "$$projectMaxBlockScanned" }))), + new BsonDocument("$match", + new BsonDocument("$expr", + new BsonDocument("$eq", + new BsonArray { "$Outpoint.OutputIndex", 0 }))), } }, { "as", "o" }