[db] Fix database missing indexes
Some checks failed
CI / Rustfmt (push) Successful in 38s
CI / Flatpak (push) Failing after 10m11s

This commit is contained in:
2026-03-19 08:40:09 -04:00
parent 94d6286ee9
commit 750cba8351
6 changed files with 146 additions and 51 deletions

View File

@ -25,8 +25,8 @@
"--share=network"
],
"env" : {
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL": "sparse",
"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_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"
@ -40,7 +40,9 @@
{
"name" : "blueprint-compiler",
"buildsystem" : "meson",
"cleanup": ["*"],
"cleanup" : [
"*"
],
"sources" : [
{
"type" : "git",
@ -55,7 +57,8 @@
"buildsystem" : "meson",
"run-tests" : true,
"config-opts" : [
"-Dprofile=development"
"-Dprofile=development",
"--libdir=lib"
],
"sources" : [
{

View 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": "../"
}
]
}
]
}

View File

@ -0,0 +1 @@
CREATE INDEX IF NOT EXISTS message_server_topic_time ON message (server, topic, data ->> '$.time');

View 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);

View File

@ -27,10 +27,10 @@ impl Db {
Ok(this)
}
fn migrate(&mut self) -> Result<()> {
self.conn
.read()
.unwrap()
.execute_batch(include_str!("./migrations/00.sql"))?;
let conn = self.conn.read().unwrap();
conn.execute_batch(include_str!("./migrations/00.sql"))?;
conn.execute_batch(include_str!("./migrations/01.sql"))?;
conn.execute_batch(include_str!("./migrations/02.sql"))?;
Ok(())
}
fn get_or_insert_server(&mut self, server: &str) -> Result<i64> {
@ -77,21 +77,41 @@ impl Db {
server: &str,
topic: &str,
since: u64,
limit: Option<u64>,
offset: Option<u64>,
) -> Result<Vec<String>, rusqlite::Error> {
let conn = self.conn.read().unwrap();
let mut stmt = conn.prepare(
let mut query = String::from(
"
SELECT data
FROM subscription sub
JOIN server s ON sub.server = s.id
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
ORDER BY m.data ->> 'time'
WHERE s.endpoint = ?1 AND m.topic = ?2 AND m.timestamp >= ?3
ORDER BY m.timestamp
",
)?;
let msgs: Result<Vec<String>, _> = stmt
.query_map(params![server, topic, since], |row| row.get(0))?
.collect();
);
if limit.is_some() {
query.push_str(" LIMIT ?4");
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
}
pub fn insert_subscription(&mut self, sub: models::Subscription) -> Result<(), Error> {

View File

@ -178,7 +178,7 @@ impl SubscriptionActor {
let messages = self
.env
.db
.list_messages(&self.model.server, &self.model.topic, 0)
.list_messages(&self.model.server, &self.model.topic, 0, None, None)
.unwrap_or_default();
let mut previous_events: Vec<ListenerEvent> = messages
.into_iter()