Skip to content

Commit

Permalink
try(backend): try hashing approach for progress update
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jul 19, 2023
1 parent ceba3c4 commit e76ebaf
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use sea_query::{
PostgresQueryBuilder, Query, SelectStatement, SqliteQueryBuilder, UnionType, Values,
};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use strum::IntoEnumIterator;
use uuid::Uuid;

Expand Down Expand Up @@ -1618,8 +1619,25 @@ impl MiscellaneousService {
input: ProgressUpdateInput,
user_id: i32,
) -> Result<IdObject> {
// TODO: Hash `input.{metadata_id,show_season_number,show_episode_number,podcast_episode_number},user_id`
// and store it in a database so that implement de-duplication.
// Hash `input.{metadata_id,show_season_number,show_episode_number,podcast_episode_number},user_id`
// and store it in a memory database to implement de-duplication. Also
// set expiry for keys in the DB to the
// `config.server.progress_update_threshold` key.
let mut hasher = Sha256::new();
hasher.update(user_id.to_be_bytes());
hasher.update(input.metadata_id.to_be_bytes());
if let Some(s) = input.show_season_number {
hasher.update(s.to_be_bytes());
}
if let Some(s) = input.show_episode_number {
hasher.update(s.to_be_bytes());
}
if let Some(s) = input.podcast_episode_number {
hasher.update(s.to_be_bytes());
}
let result = hasher.finalize();
println!("{:?}", &result);

let prev_seen = Seen::find()
.filter(seen::Column::Progress.lt(100))
.filter(seen::Column::UserId.eq(user_id))
Expand Down

0 comments on commit e76ebaf

Please sign in to comment.