mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-26 13:31:02 +00:00
Cache LOCAL_INSTANCE_USER once
This commit is contained in:
parent
e01539ef16
commit
c67b702425
1 changed files with 5 additions and 11 deletions
|
@ -11,7 +11,6 @@ use diesel::{self, result::Error::NotFound, ExpressionMethods, QueryDsl, RunQuer
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use plume_common::utils::md_to_html;
|
use plume_common::utils::md_to_html;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use tracing::error;
|
|
||||||
|
|
||||||
#[derive(Clone, Identifiable, Queryable)]
|
#[derive(Clone, Identifiable, Queryable)]
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
|
@ -110,16 +109,11 @@ impl Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cache_local_instance_user(conn: &Connection) {
|
pub fn cache_local_instance_user(conn: &Connection) {
|
||||||
let res = Self::get_local_instance_user_uncached(conn)
|
let _ = LOCAL_INSTANCE_USER.get_or_init(|| {
|
||||||
.or_else(|_| Self::create_local_instance_user(conn));
|
Self::get_local_instance_user_uncached(conn)
|
||||||
if res.is_err() {
|
.or_else(|_| Self::create_local_instance_user(conn))
|
||||||
error!("Failed to cache local instance user: {:?}", res);
|
.expect("Failed to cache local instance user")
|
||||||
return;
|
});
|
||||||
}
|
|
||||||
let user = res.expect("Unreachable");
|
|
||||||
LOCAL_INSTANCE_USER
|
|
||||||
.set(user)
|
|
||||||
.expect("Failed to set local instance user");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn page(conn: &Connection, (min, max): (i32, i32)) -> Result<Vec<Instance>> {
|
pub fn page(conn: &Connection, (min, max): (i32, i32)) -> Result<Vec<Instance>> {
|
||||||
|
|
Loading…
Reference in a new issue