mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
Avoid breaking api change, reduce api cache duration (#4610)
* Dont mark site.public_key as `serde(skip)` to avoid breaking change (fixes #4605) * Reduce cache duration for api
This commit is contained in:
parent
8e54a4a6cc
commit
1d0a6ac08f
7 changed files with 19 additions and 14 deletions
|
@ -42,7 +42,7 @@ use lemmy_utils::{
|
||||||
markdown::{markdown_check_for_blocked_urls, markdown_rewrite_image_links},
|
markdown::{markdown_check_for_blocked_urls, markdown_rewrite_image_links},
|
||||||
slurs::{build_slur_regex, remove_slurs},
|
slurs::{build_slur_regex, remove_slurs},
|
||||||
},
|
},
|
||||||
CACHE_DURATION_SHORT,
|
CACHE_DURATION_FEDERATION,
|
||||||
};
|
};
|
||||||
use moka::future::Cache;
|
use moka::future::Cache;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
@ -524,7 +524,7 @@ pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult<RegexSet>
|
||||||
static URL_BLOCKLIST: Lazy<Cache<(), RegexSet>> = Lazy::new(|| {
|
static URL_BLOCKLIST: Lazy<Cache<(), RegexSet>> = Lazy::new(|| {
|
||||||
Cache::builder()
|
Cache::builder()
|
||||||
.max_capacity(1)
|
.max_capacity(1)
|
||||||
.time_to_live(CACHE_DURATION_SHORT)
|
.time_to_live(CACHE_DURATION_FEDERATION)
|
||||||
.build()
|
.build()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ use lemmy_db_views_actor::structs::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
||||||
CACHE_DURATION_SHORT,
|
CACHE_DURATION_API,
|
||||||
VERSION,
|
VERSION,
|
||||||
};
|
};
|
||||||
use moka::future::Cache;
|
use moka::future::Cache;
|
||||||
|
@ -34,7 +34,7 @@ pub async fn get_site(
|
||||||
static CACHE: Lazy<Cache<(), GetSiteResponse>> = Lazy::new(|| {
|
static CACHE: Lazy<Cache<(), GetSiteResponse>> = Lazy::new(|| {
|
||||||
Cache::builder()
|
Cache::builder()
|
||||||
.max_capacity(1)
|
.max_capacity(1)
|
||||||
.time_to_live(CACHE_DURATION_SHORT)
|
.time_to_live(CACHE_DURATION_API)
|
||||||
.build()
|
.build()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::{LemmyError, LemmyErrorType, LemmyResult},
|
error::{LemmyError, LemmyErrorType, LemmyResult},
|
||||||
CACHE_DURATION_SHORT,
|
CACHE_DURATION_FEDERATION,
|
||||||
};
|
};
|
||||||
use moka::future::Cache;
|
use moka::future::Cache;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
@ -127,7 +127,7 @@ pub(crate) async fn local_site_data_cached(
|
||||||
static CACHE: Lazy<Cache<(), Arc<LocalSiteData>>> = Lazy::new(|| {
|
static CACHE: Lazy<Cache<(), Arc<LocalSiteData>>> = Lazy::new(|| {
|
||||||
Cache::builder()
|
Cache::builder()
|
||||||
.max_capacity(1)
|
.max_capacity(1)
|
||||||
.time_to_live(CACHE_DURATION_SHORT)
|
.time_to_live(CACHE_DURATION_FEDERATION)
|
||||||
.build()
|
.build()
|
||||||
});
|
});
|
||||||
Ok(
|
Ok(
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use lemmy_utils::{error::LemmyError, CACHE_DURATION_SHORT};
|
use lemmy_utils::{error::LemmyError, CACHE_DURATION_API};
|
||||||
use moka::future::Cache;
|
use moka::future::Cache;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl LocalSite {
|
||||||
static CACHE: Lazy<Cache<(), LocalSite>> = Lazy::new(|| {
|
static CACHE: Lazy<Cache<(), LocalSite>> = Lazy::new(|| {
|
||||||
Cache::builder()
|
Cache::builder()
|
||||||
.max_capacity(1)
|
.max_capacity(1)
|
||||||
.time_to_live(CACHE_DURATION_SHORT)
|
.time_to_live(CACHE_DURATION_API)
|
||||||
.build()
|
.build()
|
||||||
});
|
});
|
||||||
Ok(
|
Ok(
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub struct Site {
|
||||||
pub inbox_url: DbUrl,
|
pub inbox_url: DbUrl,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub private_key: Option<String>,
|
pub private_key: Option<String>,
|
||||||
#[serde(skip)]
|
// TODO: mark as `serde(skip)` in next major release as its not needed for api
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
pub instance_id: InstanceId,
|
pub instance_id: InstanceId,
|
||||||
/// If present, nsfw content is visible by default. Should be displayed by frontends/clients
|
/// If present, nsfw content is visible by default. Should be displayed by frontends/clients
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use lemmy_api_common::lemmy_utils::CACHE_DURATION_SHORT;
|
use lemmy_api_common::lemmy_utils::CACHE_DURATION_FEDERATION;
|
||||||
use lemmy_apub::{
|
use lemmy_apub::{
|
||||||
activity_lists::SharedInboxActivities,
|
activity_lists::SharedInboxActivities,
|
||||||
fetcher::{site_or_community_or_user::SiteOrCommunityOrUser, user_or_community::UserOrCommunity},
|
fetcher::{site_or_community_or_user::SiteOrCommunityOrUser, user_or_community::UserOrCommunity},
|
||||||
|
@ -169,8 +169,11 @@ pub(crate) async fn get_activity_cached(
|
||||||
|
|
||||||
/// return the most current activity id (with 1 second cache)
|
/// return the most current activity id (with 1 second cache)
|
||||||
pub(crate) async fn get_latest_activity_id(pool: &mut DbPool<'_>) -> Result<ActivityId> {
|
pub(crate) async fn get_latest_activity_id(pool: &mut DbPool<'_>) -> Result<ActivityId> {
|
||||||
static CACHE: Lazy<Cache<(), ActivityId>> =
|
static CACHE: Lazy<Cache<(), ActivityId>> = Lazy::new(|| {
|
||||||
Lazy::new(|| Cache::builder().time_to_live(CACHE_DURATION_SHORT).build());
|
Cache::builder()
|
||||||
|
.time_to_live(CACHE_DURATION_FEDERATION)
|
||||||
|
.build()
|
||||||
|
});
|
||||||
CACHE
|
CACHE
|
||||||
.try_get_with((), async {
|
.try_get_with((), async {
|
||||||
use diesel::dsl::max;
|
use diesel::dsl::max;
|
||||||
|
|
|
@ -24,9 +24,11 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
|
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
pub const CACHE_DURATION_SHORT: Duration = Duration::from_millis(500);
|
pub const CACHE_DURATION_FEDERATION: Duration = Duration::from_millis(500);
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
pub const CACHE_DURATION_SHORT: Duration = Duration::from_secs(60);
|
pub const CACHE_DURATION_FEDERATION: Duration = Duration::from_secs(60);
|
||||||
|
|
||||||
|
pub const CACHE_DURATION_API: Duration = Duration::from_secs(1);
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! location_info {
|
macro_rules! location_info {
|
||||||
|
|
Loading…
Reference in a new issue