huh, this was much easier than I expected
This commit is contained in:
parent
1f4f7698dc
commit
ceb64afd26
|
@ -3,7 +3,7 @@ An IRC bot Above All [other bots].
|
||||||
|
|
||||||
## Milestones for 0.3
|
## Milestones for 0.3
|
||||||
|
|
||||||
- [ ] Migrate quotes table to FTS5
|
- [x] Migrate quotes table to FTS5
|
||||||
- [ ] Parallel handling of messages
|
- [ ] Parallel handling of messages
|
||||||
- [x] Discord webhook emulator
|
- [x] Discord webhook emulator
|
||||||
- [x] Multiple prefixes
|
- [x] Multiple prefixes
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl DbExecutor {
|
||||||
let (tx, rx) = unbounded_channel();
|
let (tx, rx) = unbounded_channel();
|
||||||
let db = rusqlite::Connection::open(dbpath)?;
|
let db = rusqlite::Connection::open(dbpath)?;
|
||||||
db.execute(
|
db.execute(
|
||||||
"create table if not exists quotes(id integer primary key, username text not null, quote text not null)",
|
"create virtual table if not exists quotes using fts5(username, quote)",
|
||||||
[],
|
[],
|
||||||
)?;
|
)?;
|
||||||
tracing::debug!("Database connected ({})", dbpath);
|
tracing::debug!("Database connected ({})", dbpath);
|
||||||
|
@ -70,7 +70,7 @@ impl DbExecutor {
|
||||||
Task::GetQuote(tx, author) => {
|
Task::GetQuote(tx, author) => {
|
||||||
let result = if let Some(mut author) = author {
|
let result = if let Some(mut author) = author {
|
||||||
author.make_ascii_lowercase();
|
author.make_ascii_lowercase();
|
||||||
self.db.query_row("select quote,username from quotes where username glob ? order by random() limit 1", params![author], |v| Ok(Quote {quote:v.get(0)?, author:v.get(1)?}))
|
self.db.query_row("select quote,username from quotes where username match ? order by random() limit 1", params![author], |v| Ok(Quote {quote:v.get(0)?, author:v.get(1)?}))
|
||||||
} else {
|
} else {
|
||||||
self.db.query_row("select quote,username from quotes order by random() limit 1", params![], |v| Ok(Quote {quote:v.get(0)?, author:v.get(1)?}))
|
self.db.query_row("select quote,username from quotes order by random() limit 1", params![], |v| Ok(Quote {quote:v.get(0)?, author:v.get(1)?}))
|
||||||
}.optional();
|
}.optional();
|
||||||
|
@ -99,7 +99,7 @@ impl DbExecutor {
|
||||||
query: String,
|
query: String,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
) -> rusqlite::Result<Vec<Quote>> {
|
) -> rusqlite::Result<Vec<Quote>> {
|
||||||
let (quotes, oid) = self.yield_quotes_oid("select oid,quote,username from quotes where quote like '%'||?1||'%' order by oid asc limit ?", params![query, limit])?;
|
let (quotes, oid) = self.yield_quotes_oid("select oid,quote,username from quotes where quote match ? order by oid asc limit ?", params![query, limit])?;
|
||||||
searches.insert(user, (query, oid));
|
searches.insert(user, (query, oid));
|
||||||
Ok(quotes)
|
Ok(quotes)
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ impl DbExecutor {
|
||||||
} else {
|
} else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
let (quotes, new_oid) = self.yield_quotes_oid("select oid,quote,username from quotes where oid > ? and quote like '%'||?||'%' order by oid asc limit ?", params![*old_oid, &*query, limit])?;
|
let (quotes, new_oid) = self.yield_quotes_oid("select oid,quote,username from quotes where oid > ? and quote match ? order by oid asc limit ?", params![*old_oid, &*query, limit])?;
|
||||||
if new_oid != -1 {
|
if new_oid != -1 {
|
||||||
*old_oid = new_oid;
|
*old_oid = new_oid;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue