Skip to content

Commit 0aff71f

Browse files
committed
Optimize indices for expired value fix lookup.
1 parent 3b570d2 commit 0aff71f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/config.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use lightning::util::ser::Readable;
1515
use lightning_block_sync::http::HttpEndpoint;
1616
use tokio_postgres::Config;
1717

18-
pub(crate) const SCHEMA_VERSION: i32 = 12;
18+
pub(crate) const SCHEMA_VERSION: i32 = 13;
1919
pub(crate) const SYMLINK_GRANULARITY_INTERVAL: u32 = 3600 * 3; // three hours
2020
pub(crate) const MAX_SNAPSHOT_SCOPE: u32 = 3600 * 24 * 21; // three weeks
2121
// generate symlinks based on a 3-hour-granularity
@@ -143,7 +143,7 @@ pub(crate) fn db_index_creation_query() -> &'static str {
143143
CREATE INDEX IF NOT EXISTS channel_updates_scid_dir_seen_desc_with_id ON channel_updates(short_channel_id ASC, direction ASC, seen DESC) INCLUDE (id);
144144
CREATE UNIQUE INDEX IF NOT EXISTS channel_updates_key ON channel_updates (short_channel_id, direction, timestamp);
145145
CREATE INDEX IF NOT EXISTS channel_updates_seen ON channel_updates(seen);
146-
CREATE INDEX IF NOT EXISTS channel_updates_timestamp_desc ON channel_updates(timestamp DESC);
146+
CREATE INDEX IF NOT EXISTS channel_updates_scid_asc_timestamp_desc ON channel_updates(short_channel_id ASC, timestamp DESC);
147147
"
148148
}
149149

@@ -282,6 +282,12 @@ pub(crate) async fn upgrade_db(schema: i32, client: &mut tokio_postgres::Client)
282282
tx.execute("UPDATE config SET db_schema = 12 WHERE id = 1", &[]).await.unwrap();
283283
tx.commit().await.unwrap();
284284
}
285+
if schema >= 1 && schema <= 12 {
286+
let tx = client.transaction().await.unwrap();
287+
tx.execute("DROP INDEX IF EXISTS channel_updates_timestamp_desc", &[]).await.unwrap();
288+
tx.execute("UPDATE config SET db_schema = 13 WHERE id = 1", &[]).await.unwrap();
289+
tx.commit().await.unwrap();
290+
}
285291
if schema <= 1 || schema > SCHEMA_VERSION {
286292
panic!("Unknown schema in db: {}, we support up to {}", schema, SCHEMA_VERSION);
287293
}

0 commit comments

Comments
 (0)