bookdata/goodreads/
users.rs

1//! Support for GoodReads user identifiers.
2use anyhow::Result;
3use log::*;
4
5use crate::{ids::index::IdIndex, prelude::BDPath};
6
7const GR_USER_FILE: BDPath<'static> = BDPath::new("goodreads/gr-users.parquet");
8const UID_COL: &'static str = "user";
9const UHASH_COL: &'static str = "user_hash";
10
11pub type UserIndex = IdIndex<String>;
12
13pub fn save_user_index(users: &UserIndex) -> Result<()> {
14    let path = GR_USER_FILE.resolve()?;
15    info!("saving {} users to {}", users.len(), path.display());
16    users.save(&path, UID_COL, UHASH_COL)?;
17    Ok(())
18}
19
20pub fn load_user_index() -> Result<UserIndex> {
21    let path = GR_USER_FILE.resolve()?;
22    let users = IdIndex::load(&path, UID_COL, UHASH_COL)?;
23    info!("loaded {} users from {}", users.len(), path.display());
24    Ok(users)
25}