[db] Fix database missing indexes
This commit is contained in:
@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"id": "com.ranfdev.Notify.Devel",
|
"id" : "com.ranfdev.Notify.Devel",
|
||||||
"runtime": "org.gnome.Platform",
|
"runtime" : "org.gnome.Platform",
|
||||||
"runtime-version": "47",
|
"runtime-version" : "47",
|
||||||
"sdk": "org.gnome.Sdk",
|
"sdk" : "org.gnome.Sdk",
|
||||||
"sdk-extensions": [
|
"sdk-extensions" : [
|
||||||
"org.freedesktop.Sdk.Extension.rust-stable",
|
"org.freedesktop.Sdk.Extension.rust-stable",
|
||||||
"org.freedesktop.Sdk.Extension.llvm18"
|
"org.freedesktop.Sdk.Extension.llvm18"
|
||||||
],
|
],
|
||||||
"command": "notify",
|
"command" : "notify",
|
||||||
"finish-args": [
|
"finish-args" : [
|
||||||
"--share=ipc",
|
"--share=ipc",
|
||||||
"--share=network",
|
"--share=network",
|
||||||
"--socket=fallback-x11",
|
"--socket=fallback-x11",
|
||||||
@ -19,48 +19,51 @@
|
|||||||
"--env=RUST_BACKTRACE=1",
|
"--env=RUST_BACKTRACE=1",
|
||||||
"--talk-name=org.freedesktop.Notifications"
|
"--talk-name=org.freedesktop.Notifications"
|
||||||
],
|
],
|
||||||
"build-options": {
|
"build-options" : {
|
||||||
"append-path": "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm18/bin",
|
"append-path" : "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm18/bin",
|
||||||
"build-args": [
|
"build-args" : [
|
||||||
"--share=network"
|
"--share=network"
|
||||||
],
|
],
|
||||||
"env": {
|
"env" : {
|
||||||
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL": "sparse",
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER" : "clang",
|
||||||
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER": "clang",
|
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL" : "sparse",
|
||||||
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold",
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS" : "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold",
|
||||||
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER": "clang",
|
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER" : "clang",
|
||||||
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold"
|
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS" : "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold"
|
||||||
},
|
},
|
||||||
"test-args": [
|
"test-args" : [
|
||||||
"--socket=x11",
|
"--socket=x11",
|
||||||
"--share=network"
|
"--share=network"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"modules": [
|
"modules" : [
|
||||||
{
|
{
|
||||||
"name": "blueprint-compiler",
|
"name" : "blueprint-compiler",
|
||||||
"buildsystem": "meson",
|
"buildsystem" : "meson",
|
||||||
"cleanup": ["*"],
|
"cleanup" : [
|
||||||
"sources": [
|
"*"
|
||||||
{
|
],
|
||||||
"type": "git",
|
"sources" : [
|
||||||
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
|
{
|
||||||
"tag": "v0.14.0",
|
"type" : "git",
|
||||||
"commit": "8e10fcf8692108b9d4ab78f41086c5d7773ef864"
|
"url" : "https://gitlab.gnome.org/jwestman/blueprint-compiler",
|
||||||
}
|
"tag" : "v0.14.0",
|
||||||
]
|
"commit" : "8e10fcf8692108b9d4ab78f41086c5d7773ef864"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "notify",
|
"name" : "notify",
|
||||||
"buildsystem": "meson",
|
"buildsystem" : "meson",
|
||||||
"run-tests": true,
|
"run-tests" : true,
|
||||||
"config-opts": [
|
"config-opts" : [
|
||||||
"-Dprofile=development"
|
"-Dprofile=development",
|
||||||
|
"--libdir=lib"
|
||||||
],
|
],
|
||||||
"sources": [
|
"sources" : [
|
||||||
{
|
{
|
||||||
"type": "dir",
|
"type" : "dir",
|
||||||
"path": "../"
|
"path" : "../"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
68
build-aux/com.ranfdev.Notify.Devel.json~
Normal file
68
build-aux/com.ranfdev.Notify.Devel.json~
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
{
|
||||||
|
"id": "com.ranfdev.Notify.Devel",
|
||||||
|
"runtime": "org.gnome.Platform",
|
||||||
|
"runtime-version": "47",
|
||||||
|
"sdk": "org.gnome.Sdk",
|
||||||
|
"sdk-extensions": [
|
||||||
|
"org.freedesktop.Sdk.Extension.rust-stable",
|
||||||
|
"org.freedesktop.Sdk.Extension.llvm18"
|
||||||
|
],
|
||||||
|
"command": "notify",
|
||||||
|
"finish-args": [
|
||||||
|
"--share=ipc",
|
||||||
|
"--share=network",
|
||||||
|
"--socket=fallback-x11",
|
||||||
|
"--socket=wayland",
|
||||||
|
"--device=dri",
|
||||||
|
"--env=RUST_LOG=notify=debug,ntfy_daemon=debug",
|
||||||
|
"--env=G_MESSAGES_DEBUG=none",
|
||||||
|
"--env=RUST_BACKTRACE=1",
|
||||||
|
"--talk-name=org.freedesktop.Notifications"
|
||||||
|
],
|
||||||
|
"build-options": {
|
||||||
|
"append-path": "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm18/bin",
|
||||||
|
"build-args": [
|
||||||
|
"--share=network"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL": "sparse",
|
||||||
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER": "clang",
|
||||||
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold",
|
||||||
|
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER": "clang",
|
||||||
|
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold"
|
||||||
|
},
|
||||||
|
"test-args": [
|
||||||
|
"--socket=x11",
|
||||||
|
"--share=network"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"name": "blueprint-compiler",
|
||||||
|
"buildsystem": "meson",
|
||||||
|
"cleanup": ["*"],
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
|
||||||
|
"tag": "v0.14.0",
|
||||||
|
"commit": "8e10fcf8692108b9d4ab78f41086c5d7773ef864"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "notify",
|
||||||
|
"buildsystem": "meson",
|
||||||
|
"run-tests": true,
|
||||||
|
"config-opts": [
|
||||||
|
"-Dprofile=development"
|
||||||
|
],
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"type": "dir",
|
||||||
|
"path": "../"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
1
ntfy-daemon/src/message_repo/migrations/01.sql
Normal file
1
ntfy-daemon/src/message_repo/migrations/01.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
CREATE INDEX IF NOT EXISTS message_server_topic_time ON message (server, topic, data ->> '$.time');
|
||||||
3
ntfy-daemon/src/message_repo/migrations/02.sql
Normal file
3
ntfy-daemon/src/message_repo/migrations/02.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE message ADD COLUMN timestamp INTEGER AS (data ->> '$.time') STORED;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS message_server_topic_timestamp ON message (server, topic, timestamp);
|
||||||
@ -27,10 +27,10 @@ impl Db {
|
|||||||
Ok(this)
|
Ok(this)
|
||||||
}
|
}
|
||||||
fn migrate(&mut self) -> Result<()> {
|
fn migrate(&mut self) -> Result<()> {
|
||||||
self.conn
|
let conn = self.conn.read().unwrap();
|
||||||
.read()
|
conn.execute_batch(include_str!("./migrations/00.sql"))?;
|
||||||
.unwrap()
|
conn.execute_batch(include_str!("./migrations/01.sql"))?;
|
||||||
.execute_batch(include_str!("./migrations/00.sql"))?;
|
conn.execute_batch(include_str!("./migrations/02.sql"))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn get_or_insert_server(&mut self, server: &str) -> Result<i64> {
|
fn get_or_insert_server(&mut self, server: &str) -> Result<i64> {
|
||||||
@ -77,21 +77,41 @@ impl Db {
|
|||||||
server: &str,
|
server: &str,
|
||||||
topic: &str,
|
topic: &str,
|
||||||
since: u64,
|
since: u64,
|
||||||
|
limit: Option<u64>,
|
||||||
|
offset: Option<u64>,
|
||||||
) -> Result<Vec<String>, rusqlite::Error> {
|
) -> Result<Vec<String>, rusqlite::Error> {
|
||||||
let conn = self.conn.read().unwrap();
|
let conn = self.conn.read().unwrap();
|
||||||
let mut stmt = conn.prepare(
|
let mut query = String::from(
|
||||||
"
|
"
|
||||||
SELECT data
|
SELECT data
|
||||||
FROM subscription sub
|
FROM subscription sub
|
||||||
JOIN server s ON sub.server = s.id
|
JOIN server s ON sub.server = s.id
|
||||||
JOIN message m ON m.server = sub.server AND m.topic = sub.topic
|
JOIN message m ON m.server = sub.server AND m.topic = sub.topic
|
||||||
WHERE s.endpoint = ?1 AND m.topic = ?2 AND m.data ->> 'time' >= ?3
|
WHERE s.endpoint = ?1 AND m.topic = ?2 AND m.timestamp >= ?3
|
||||||
ORDER BY m.data ->> 'time'
|
ORDER BY m.timestamp
|
||||||
",
|
",
|
||||||
)?;
|
);
|
||||||
let msgs: Result<Vec<String>, _> = stmt
|
if limit.is_some() {
|
||||||
.query_map(params![server, topic, since], |row| row.get(0))?
|
query.push_str(" LIMIT ?4");
|
||||||
.collect();
|
if offset.is_some() {
|
||||||
|
query.push_str(" OFFSET ?5");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut stmt = conn.prepare(&query)?;
|
||||||
|
|
||||||
|
let msgs: Result<Vec<String>, _> = if let (Some(limit), Some(offset)) = (limit, offset) {
|
||||||
|
stmt.query_map(params![server, topic, since, limit, offset], |row| {
|
||||||
|
row.get(0)
|
||||||
|
})?
|
||||||
|
.collect()
|
||||||
|
} else if let Some(limit) = limit {
|
||||||
|
stmt.query_map(params![server, topic, since, limit], |row| row.get(0))?
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
stmt.query_map(params![server, topic, since], |row| row.get(0))?
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
msgs
|
msgs
|
||||||
}
|
}
|
||||||
pub fn insert_subscription(&mut self, sub: models::Subscription) -> Result<(), Error> {
|
pub fn insert_subscription(&mut self, sub: models::Subscription) -> Result<(), Error> {
|
||||||
|
|||||||
@ -177,9 +177,9 @@ impl SubscriptionActor {
|
|||||||
debug!(topic=?self.model.topic, "attaching new listener");
|
debug!(topic=?self.model.topic, "attaching new listener");
|
||||||
let messages = self
|
let messages = self
|
||||||
.env
|
.env
|
||||||
.db
|
.db
|
||||||
.list_messages(&self.model.server, &self.model.topic, 0)
|
.list_messages(&self.model.server, &self.model.topic, 0, None, None)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let mut previous_events: Vec<ListenerEvent> = messages
|
let mut previous_events: Vec<ListenerEvent> = messages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|msg| {
|
.filter_map(|msg| {
|
||||||
|
|||||||
Reference in New Issue
Block a user