forked from didirus/AstralRinth
Add redis caching to getting user notifications and projects [MOD-540] (#723)
* Add redis caching to getting a user's project ids * Run `cargo sqlx prepare` to update the sqlx-data.json * Add redis caching for getting user notifications * Fix new clippy warnings * Remove log that shouldn't have been committed * Batch insert of notifications (untested) * sqlx prepare... * Fix merge conflict things and use new redis struct * Fix bug with calling delete_many without any elements (caught by tests) * cargo sqlx prepare * Add tests around cache invalidation (and fix bug they caught!) * Some test reorg based on code review suggestions
This commit is contained in:
@@ -213,12 +213,7 @@ impl Session {
|
||||
|
||||
for session in db_sessions {
|
||||
redis
|
||||
.set(
|
||||
SESSIONS_NAMESPACE,
|
||||
session.id.0,
|
||||
serde_json::to_string(&session)?,
|
||||
None,
|
||||
)
|
||||
.set_serialized_to_json(SESSIONS_NAMESPACE, session.id.0, &session, None)
|
||||
.await?;
|
||||
redis
|
||||
.set(
|
||||
@@ -244,9 +239,8 @@ impl Session {
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let res = redis
|
||||
.get::<String, _>(SESSIONS_USERS_NAMESPACE, user_id.0)
|
||||
.await?
|
||||
.and_then(|x| serde_json::from_str::<Vec<i64>>(&x).ok());
|
||||
.get_deserialized_from_json::<Vec<i64>, _>(SESSIONS_USERS_NAMESPACE, user_id.0)
|
||||
.await?;
|
||||
|
||||
if let Some(res) = res {
|
||||
return Ok(res.into_iter().map(SessionId).collect());
|
||||
@@ -268,12 +262,7 @@ impl Session {
|
||||
.await?;
|
||||
|
||||
redis
|
||||
.set(
|
||||
SESSIONS_USERS_NAMESPACE,
|
||||
user_id.0,
|
||||
serde_json::to_string(&db_sessions)?,
|
||||
None,
|
||||
)
|
||||
.set_serialized_to_json(SESSIONS_USERS_NAMESPACE, user_id.0, &db_sessions, None)
|
||||
.await?;
|
||||
|
||||
Ok(db_sessions)
|
||||
|
||||
Reference in New Issue
Block a user