Fix redis pool timeout (#669)

* Fix redis pool timeout

* remove search dep project issues

* run fmt + prep
This commit is contained in:
Geometrically
2023-08-06 15:34:03 -07:00
committed by GitHub
parent 1f4ad732fd
commit e9f5bd4ac1
8 changed files with 191 additions and 219 deletions

View File

@@ -21,7 +21,7 @@ pub async fn fetch_bearer(token: &str, uhs: &str) -> Result<String, Authenticati
.get("access_token")
.and_then(serde_json::Value::as_str)
.map(String::from)
.ok_or(AuthenticationError::Custom(
format!("Response didn't contain valid bearer token. body: {body}"),
))
.ok_or(AuthenticationError::Custom(format!(
"Response didn't contain valid bearer token. body: {body}"
)))
}

View File

@@ -349,6 +349,7 @@ pub async fn process_payout(
_ => weekday_amount,
};
let mut clear_cache_users = Vec::new();
for (id, project) in projects_map {
if let Some(value) = &multipliers.values.get(&(id as u64)) {
let project_multiplier: Decimal =
@@ -356,8 +357,6 @@ pub async fn process_payout(
let sum_splits: Decimal = project.team_members.iter().map(|x| x.1).sum();
let mut clear_cache_users = Vec::new();
if sum_splits > Decimal::ZERO {
for (user_id, split) in project.team_members {
let payout: Decimal = payout * project_multiplier * (split / sum_splits);
@@ -387,22 +386,25 @@ pub async fn process_payout(
)
.execute(&mut *transaction)
.await?;
clear_cache_users.push(user_id);
}
}
}
crate::database::models::User::clear_caches(
&clear_cache_users
.into_iter()
.map(|x| (crate::database::models::UserId(x), None))
.collect::<Vec<_>>(),
redis,
)
.await?;
}
}
if !clear_cache_users.is_empty() {
crate::database::models::User::clear_caches(
&clear_cache_users
.into_iter()
.map(|x| (crate::database::models::UserId(x), None))
.collect::<Vec<_>>(),
redis,
)
.await?;
}
transaction.commit().await?;
Ok(())

View File

@@ -1,21 +1,21 @@
use actix_cors::Cors;
use crate::file_hosting::FileHostingError;
use crate::routes::analytics::{page_view_ingest, playtime_ingest};
use crate::util::cors::default_cors;
use crate::util::env::parse_strings_from_var;
use actix_cors::Cors;
use actix_files::Files;
use actix_web::http::StatusCode;
use actix_web::{web, HttpResponse};
use futures::FutureExt;
use crate::routes::analytics::{page_view_ingest, playtime_ingest};
use crate::util::env::parse_strings_from_var;
pub mod v2;
pub mod v3;
mod analytics;
mod index;
mod maven;
mod not_found;
mod updates;
mod analytics;
pub use self::not_found::not_found;
@@ -40,7 +40,7 @@ pub fn root_config(cfg: &mut web::ServiceConfig) {
allowed_origins.contains(&"*".to_string())
|| allowed_origins
.contains(&origin.to_str().unwrap_or_default().to_string())
.contains(&origin.to_str().unwrap_or_default().to_string())
})
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![

View File

@@ -135,7 +135,9 @@ pub async fn count_download(
.headers
.clone()
.into_iter()
.filter(|x| !crate::routes::analytics::FILTERED_HEADERS.contains(&&*x.0.to_lowercase()))
.filter(|x| {
!crate::routes::analytics::FILTERED_HEADERS.contains(&&*x.0.to_lowercase())
})
.collect(),
})
.await;

View File

@@ -4,7 +4,6 @@ use log::info;
use super::IndexingError;
use crate::database::models::ProjectId;
use crate::search::UploadSearchProject;
use serde::Deserialize;
use sqlx::postgres::PgPool;
pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchProject>, IndexingError> {
@@ -22,8 +21,7 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchProject>, Index
ARRAY_AGG(DISTINCT lo.loader) filter (where lo.loader is not null) loaders,
ARRAY_AGG(DISTINCT gv.version) filter (where gv.version is not null) versions,
ARRAY_AGG(DISTINCT mg.image_url) filter (where mg.image_url is not null and mg.featured is false) gallery,
ARRAY_AGG(DISTINCT mg.image_url) filter (where mg.image_url is not null and mg.featured is true) featured_gallery,
JSONB_AGG(DISTINCT jsonb_build_object('id', mdep.id, 'dep_type', d.dependency_type)) filter (where mdep.id is not null) dependencies
ARRAY_AGG(DISTINCT mg.image_url) filter (where mg.image_url is not null and mg.featured is true) featured_gallery
FROM mods m
LEFT OUTER JOIN mods_categories mc ON joining_mod_id = m.id
LEFT OUTER JOIN categories c ON mc.joining_category_id = c.id
@@ -33,8 +31,6 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchProject>, Index
LEFT OUTER JOIN loaders_versions lv ON lv.version_id = v.id
LEFT OUTER JOIN loaders lo ON lo.id = lv.loader_id
LEFT OUTER JOIN mods_gallery mg ON mg.mod_id = m.id
LEFT OUTER JOIN dependencies d ON d.dependent_id = v.id
LEFT OUTER JOIN mods mdep ON mdep.id = d.mod_dependency_id
INNER JOIN project_types pt ON pt.id = m.project_type
INNER JOIN side_types cs ON m.client_side = cs.id
INNER JOIN side_types ss ON m.server_side = ss.id
@@ -72,21 +68,6 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchProject>, Index
_ => false,
};
#[derive(Deserialize)]
struct TempDependency {
id: ProjectId,
dep_type: String
}
let dependencies = serde_json::from_value::<Vec<TempDependency>>(
m.dependencies.unwrap_or_default(),
)
.ok()
.unwrap_or_default()
.into_iter()
.map(|x| format!("{}-{}", crate::models::ids::ProjectId::from(x.id), x.dep_type))
.collect();
UploadSearchProject {
project_id: project_id.to_string(),
title: m.title,
@@ -112,7 +93,6 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchProject>, Index
open_source,
color: m.color.map(|x| x as u32),
featured_gallery: m.featured_gallery.unwrap_or_default().first().cloned(),
dependencies,
}
}))
})

View File

@@ -181,7 +181,6 @@ const DEFAULT_DISPLAYED_ATTRIBUTES: &[&str] = &[
"gallery",
"featured_gallery",
"color",
"dependencies",
];
const DEFAULT_SEARCHABLE_ATTRIBUTES: &[&str] = &["title", "description", "author", "slug"];
@@ -202,7 +201,6 @@ const DEFAULT_ATTRIBUTES_FOR_FACETING: &[&str] = &[
"project_id",
"open_source",
"color",
"dependencies",
];
const DEFAULT_SORTABLE_ATTRIBUTES: &[&str] =

View File

@@ -99,8 +99,6 @@ pub struct UploadSearchProject {
pub modified_timestamp: i64,
pub open_source: bool,
pub color: Option<u32>,
/// format: {project_id}-{dep_type}
pub dependencies: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug)]
@@ -136,8 +134,6 @@ pub struct ResultSearchProject {
pub gallery: Vec<String>,
pub featured_gallery: Option<String>,
pub color: Option<u32>,
/// format: {project_id}-{dep_type}
pub dependencies: Vec<String>,
}
pub async fn search_for_project(