Skip to content

Commit 484fc21

Browse files
committed
0.13.1 - Cache Indices
1 parent ad7a089 commit 484fc21

File tree

7 files changed

+130
-53
lines changed

7 files changed

+130
-53
lines changed

Cargo.lock

Lines changed: 100 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vrc-log"
3-
version = "0.13.0"
3+
version = "0.13.1"
44
authors = ["Shayne Hartford <shaybox@shaybox.com>"]
55
edition = "2021"
66
description = "VRChat Local Avatar ID Logger"

src/provider/avtrdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{time::Duration, vec};
33
use anyhow::{bail, Result};
44
use async_trait::async_trait;
55
use reqwest::{Client, StatusCode, Url};
6-
use serde::{Deserialize, Serialize};
6+
use serde::Deserialize;
77
use serde_json::{json, Value};
88

99
use crate::{

src/provider/cache.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,25 @@ impl Cache {
5656
ADD COLUMN updated_at DATETIME
5757
", [])?;
5858
}
59+
}
5960

60-
#[rustfmt::skip] // Prevent a large burst after updating
61-
connection.execute("
62-
UPDATE avatars
63-
SET updated_at = datetime('now', '-31 days')
64-
WHERE updated_at IS NULL
65-
", [])?;
66-
67-
// Print cache statistics
68-
if let Ok(mut statement) = connection.prepare("SELECT COUNT(*) FROM avatars") {
69-
if let Ok(count) = statement.query_row([], |row| row.get::<_, i64>(0)) {
70-
info!("{} Cached Avatars", count);
71-
}
61+
#[rustfmt::skip] // Prevent a large burst after updating
62+
connection.execute("
63+
UPDATE avatars
64+
SET updated_at = datetime('now', '-31 days')
65+
WHERE updated_at IS NULL
66+
", [])?;
67+
68+
#[rustfmt::skip] // Speed up queries on large databases
69+
connection.execute("
70+
CREATE INDEX IF NOT EXISTS idx_avatars_updated_at
71+
ON avatars(updated_at)
72+
", [])?;
73+
74+
// Print cache statistics
75+
if let Ok(mut statement) = connection.prepare("SELECT COUNT(*) FROM avatars") {
76+
if let Ok(count) = statement.query_row([], |row| row.get::<_, i64>(0)) {
77+
info!("{} Cached Avatars", count);
7278
}
7379
}
7480

@@ -89,9 +95,10 @@ impl Provider for Cache {
8995
async fn check_avatar_id(&self, avatar_id: &str) -> Result<bool> {
9096
let id = avatar_id.to_string();
9197
let query = "
92-
SELECT 1 FROM avatars
93-
WHERE id = (?) AND updated_at >= datetime('now', '-30 days')
94-
LIMIT 1
98+
SELECT EXISTS(
99+
SELECT 1 FROM avatars
100+
WHERE id = ? AND updated_at >= datetime('now', '-30 days')
101+
)
95102
";
96103

97104
let is_ok = self

src/provider/vrcdb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::{collections::HashMap, time::Duration};
1+
use std::time::Duration;
22

33
use anyhow::{bail, Result};
44
use async_trait::async_trait;
55
use reqwest::{Client, StatusCode};
66
use serde_json::json;
77

88
use crate::{
9-
provider::{avtrdb::AvtrDB, Provider, ProviderKind},
9+
provider::{Provider, ProviderKind},
1010
settings::Settings,
1111
USER_AGENT,
1212
};

0 commit comments

Comments
 (0)