From ecc200bf8aaae77d7682d8196441b857adbf88b9 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Thu, 8 Feb 2024 14:11:58 +0200 Subject: [PATCH] feat: add index on events for faster revision id (#6170) On all pods and instances, we run the same revision update query every second. It is relatively fast when the application has started. This is the single most ran query in unleash. Benchmarks: 1. Running pod with existing revisionID: - old 5.5ms - new 0.028ms 2. New pod without existing revisionID - old 9.329ms - new 0.033ms This query is getting optimized https://github.com/Unleash/unleash/blob/7e66a79f9f6f2c6f2475bfd723ea938bbd4fb0f6/src/lib/features/events/event-store.ts#L161 --- ...20240208130439-events-revision-id-index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/migrations/20240208130439-events-revision-id-index.js diff --git a/src/migrations/20240208130439-events-revision-id-index.js b/src/migrations/20240208130439-events-revision-id-index.js new file mode 100644 index 0000000000..13357aaecc --- /dev/null +++ b/src/migrations/20240208130439-events-revision-id-index.js @@ -0,0 +1,19 @@ +'use strict'; + +exports.up = function(db, cb) { + db.runSql( + ` + CREATE INDEX IF NOT EXISTS idx_events_feature_type_id ON events (id) + WHERE feature_name IS NOT NULL + OR type IN ('segment-updated', 'feature_import', 'features-imported'); + + `, + cb, + ); +}; + +exports.down = function(db, cb) { + db.runSql(` + DROP INDEX IF EXISTS idx_events_feature_type_id; + `, cb); +};