From 683e980ccdea378eb13c2d667e4cbc35e0ad9e28 Mon Sep 17 00:00:00 2001 From: loothero Date: Sat, 14 Oct 2023 03:18:01 +0000 Subject: [PATCH] adds indexes to mongodb to improve performance --- indexer/goerli-compose.yaml | 1 + indexer/scripts/mongo-init/init-mongo.js | 38 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 indexer/scripts/mongo-init/init-mongo.js diff --git a/indexer/goerli-compose.yaml b/indexer/goerli-compose.yaml index 47a4f79a6..bc281caf9 100644 --- a/indexer/goerli-compose.yaml +++ b/indexer/goerli-compose.yaml @@ -8,6 +8,7 @@ services: - "27017:27017" volumes: - mongo_data:/data/db + - ./scripts/mongo-init:/docker-entrypoint-initdb.d environment: MONGO_INITDB_ROOT_USERNAME: mongo MONGO_INITDB_ROOT_PASSWORD: mongo diff --git a/indexer/scripts/mongo-init/init-mongo.js b/indexer/scripts/mongo-init/init-mongo.js new file mode 100644 index 000000000..c79b1380b --- /dev/null +++ b/indexer/scripts/mongo-init/init-mongo.js @@ -0,0 +1,38 @@ +db = db.getSiblingDB('mongo_goerli'); + +// +// add indexes +// +// items +db.items.createIndex({ "_cursor.to": 1, "adventurerId": 1, "item": 1}); +db.items.createIndex({ "adventurerId": 1, "item": 1}); +db.items.createIndex({ "_cursor.from": 1 }); +db.items.createIndex({ "_cursor.to": 1 }); + +// adventurers +db.adventurers.createIndex({ "_cursor.to": 1, "adventurerId": 1 }); +db.adventurers.createIndex({ "_cursor.from": 1 }); +db.adventurers.createIndex({ "_cursor.to": 1 }); +db.adventurers.createIndex({ "xp": -1 }); + +// battles +db.battles.createIndex({ "_cursor.to": 1, "adventurerId": 1 }); +db.battles.createIndex({ "_cursor.from": 1 }); +db.battles.createIndex({ "_cursor.to": 1 }); + +// beasts +db.beasts.createIndex({ "_cursor.to": 1, "adventurerId": 1 }); +db.beasts.createIndex({ "_cursor.from": 1 }); +db.beasts.createIndex({ "_cursor.to": 1 }); + +// discoveries +db.discoveries.createIndex({ "_cursor.to": 1, "adventurerId": 1 }); +db.discoveries.createIndex({ "_cursor.from": 1 }); +db.discoveries.createIndex({ "_cursor.to": 1 }); + +// scores +db.scores.createIndex({ "_cursor.to": 1, "adventurerId": 1 }); +db.scores.createIndex({ "_cursor.from": 1 }); +db.scores.createIndex({ "_cursor.to": 1 }); +db.scores.createIndex({ "xp": -1}); +db.scores.createIndex({ "rank": -1});