mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 00:55:25 +00:00
redis compression (#6769)
* feat(labrinth): encode/decode redis values with postcard, add version in namespaces * chore(labrinth): split cache ex special cases without version * chore(labrinth): simplify get_many * fix: tombi * feat(labrinth): compression support * chore(labrinth): cleanup redis ser/de * fix(labrinth): use get_deserialized in tests
This commit is contained in:
@@ -18,9 +18,11 @@ use common::environment::{
|
||||
use common::permissions::{PermissionsTest, PermissionsTestContext};
|
||||
use futures::StreamExt;
|
||||
use hex::ToHex;
|
||||
use labrinth::database::models::DBProjectId;
|
||||
use labrinth::database::models::project_item::{
|
||||
PROJECTS_NAMESPACE, PROJECTS_SLUGS_NAMESPACE,
|
||||
PROJECTS_NAMESPACE, PROJECTS_SLUGS_NAMESPACE, ProjectQueryResult,
|
||||
};
|
||||
use labrinth::database::redis::RedisValue;
|
||||
use labrinth::models::ids::ProjectId;
|
||||
use labrinth::models::teams::ProjectPermissions;
|
||||
use labrinth::util::actix::{MultipartSegment, MultipartSegmentData};
|
||||
@@ -67,19 +69,21 @@ async fn test_get_project() {
|
||||
Some(parse_base62(alpha_project_id).unwrap() as i64)
|
||||
);
|
||||
|
||||
let cached_project = redis_pool
|
||||
.get(
|
||||
let cached_project: RedisValue<
|
||||
ProjectQueryResult,
|
||||
DBProjectId,
|
||||
String,
|
||||
> = redis_pool
|
||||
.get_deserialized(
|
||||
PROJECTS_NAMESPACE,
|
||||
&parse_base62(alpha_project_id).unwrap().to_string(),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let cached_project: serde_json::Value =
|
||||
serde_json::from_str(&cached_project).unwrap();
|
||||
assert_eq!(
|
||||
cached_project["val"]["inner"]["slug"],
|
||||
json!(alpha_project_slug)
|
||||
cached_project.value().inner.slug.as_ref(),
|
||||
Some(alpha_project_slug)
|
||||
);
|
||||
|
||||
// Make the request again, this time it should be cached
|
||||
|
||||
@@ -14,7 +14,11 @@ use common::asserts::assert_common_version_ids;
|
||||
use common::database::USER_USER_PAT;
|
||||
use common::environment::{with_test_environment, with_test_environment_all};
|
||||
use futures::StreamExt;
|
||||
use labrinth::database::models::version_item::VERSIONS_NAMESPACE;
|
||||
use labrinth::database::models::DBVersionId;
|
||||
use labrinth::database::models::version_item::{
|
||||
VERSIONS_NAMESPACE, VersionQueryResult,
|
||||
};
|
||||
use labrinth::database::redis::RedisValue;
|
||||
use labrinth::models::ids::VersionId;
|
||||
use labrinth::models::projects::{
|
||||
Dependency, DependencyType, VersionStatus, VersionType,
|
||||
@@ -47,18 +51,20 @@ async fn test_get_version() {
|
||||
assert_eq!(&version.id.to_string(), alpha_version_id);
|
||||
|
||||
let mut redis_conn = test_env.db.redis_pool.connect().await.unwrap();
|
||||
let cached_project = redis_conn
|
||||
.get(
|
||||
let cached_version: RedisValue<
|
||||
VersionQueryResult,
|
||||
DBVersionId,
|
||||
String,
|
||||
> = redis_conn
|
||||
.get_deserialized(
|
||||
VERSIONS_NAMESPACE,
|
||||
&parse_base62(alpha_version_id).unwrap().to_string(),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let cached_project: serde_json::Value =
|
||||
serde_json::from_str(&cached_project).unwrap();
|
||||
assert_eq!(
|
||||
cached_project["val"]["inner"]["project_id"],
|
||||
cached_version.value().inner.project_id.0,
|
||||
json!(parse_base62(alpha_project_id).unwrap())
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user