Skip to content

Commit

Permalink
fix(service): user details from redis (#95)
Browse files Browse the repository at this point in the history
* Experiment

* Fix new user details indexing
  • Loading branch information
SHAcollision authored Aug 30, 2024
1 parent 44fc831 commit ca3ac6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
models::{
post::PostDetails,
pubky_app::{traits::Validatable, PubkyAppPost, PubkyAppUser},
traits::Collection,
user::{PubkyId, UserCounts, UserDetails},
},
reindex::{reindex_post, reindex_user},
Expand Down Expand Up @@ -167,6 +168,7 @@ impl Event {

// Reindex to sorted sets and other indexes
reindex_user(&user_id).await?;
UserDetails::to_index(&[user_id.as_ref()], vec![Some(user_details)]).await?;
}
ResourceType::Post => {
// Process Post resource and update the databases
Expand Down
22 changes: 19 additions & 3 deletions src/models/user/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,25 @@ fn deserialize_user_links<'de, D>(deserializer: D) -> Result<Option<Vec<UserLink
where
D: Deserializer<'de>,
{
let s: String = String::deserialize(deserializer)?;
let urls: Option<Vec<UserLink>> = serde_json::from_str(&s).map_err(serde::de::Error::custom)?;
Ok(urls)
// Deserialize into serde_json::Value first
let value = serde_json::Value::deserialize(deserializer)?;

// Handle both cases
match value {
serde_json::Value::String(s) => {
// If it's a string, parse the string as JSON
let urls: Option<Vec<UserLink>> =
serde_json::from_str(&s).map_err(serde::de::Error::custom)?;
Ok(urls)
}
serde_json::Value::Array(arr) => {
// If it's already an array, deserialize it directly
let urls: Vec<UserLink> = serde_json::from_value(serde_json::Value::Array(arr))
.map_err(serde::de::Error::custom)?;
Ok(Some(urls))
}
_ => Err(serde::de::Error::custom("Expected a string or an array")),
}
}

impl UserDetails {
Expand Down

0 comments on commit ca3ac6c

Please sign in to comment.