enhance: compact & upgrade database

This commit is contained in:
mokurin000
2025-08-02 22:13:04 +08:00
parent 0b2bf20e50
commit 0d9c8c79b4
3 changed files with 8 additions and 3 deletions

View File

@@ -3,9 +3,12 @@ use std::sync::LazyLock;
use redb::{ReadTransaction, Table, TableDefinition, WriteTransaction};
static DATABASE: LazyLock<redb::Database> = LazyLock::new(|| {
redb::Database::builder()
let mut db = redb::Database::builder()
.create("players.redb")
.expect("failed to open database")
.expect("failed to open database");
_ = db.upgrade();
_ = db.compact();
db
});
pub const PLAYERS: TableDefinition<'_, u32, Vec<u8>> = redb::TableDefinition::new("players");

View File

@@ -44,6 +44,9 @@ static EARLY_QUIT: AtomicBool = AtomicBool::new(false);
async fn main() -> Result<(), Box<dyn snafu::Error>> {
nyquest_preset::register();
#[cfg(feature = "fetchall")]
let _ = cache::init_db();
let logger = spdlog::default_logger().fork_with(|log| {
log.set_level_filter(MoreSevereEqual(if cfg!(debug_assertions) {
Level::Debug

View File

@@ -90,7 +90,6 @@ where
A::Response: Encode + for<'a> BorrowDecode<'a, ()> + HasUid,
{
let user_ids = user_ids.into();
let _ = cache::init_db();
let read = cache::read_txn()?;
let write = cache::write_txn()?;
let config = sdgb_api::bincode::config::Configuration::<