Fetch Mastery Points from the Riot API and add the champion sort preference (#76)
The tracker asks Riot for each Account's champion mastery (platform host) right after a successful sync, and after a Match fetched by id is added, so no new polling. Lists are stored per Account in one transaction and read back with Tracker::mastery (None = never fetched). A failed fetch keeps the last values and records no problem. Preferences gain champion_sort (mastery or name). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
50c0427958
commit
5ce8c777c4
9 files changed
+593
-4
No files matched your search
@@ -142,6 +142,11 @@ pub struct FakeHistory {
|
||||
fetches: Arc<AtomicUsize>,
|
||||
listed: Arc<AtomicUsize>,
|
||||
calls: Arc<AtomicUsize>,
|
||||
/// Mastery Points by puuid, as Riot lists them (champions with points only).
|
||||
mastery: Mutex<HashMap<String, Vec<(u32, u64)>>>,
|
||||
/// Mastery requests fail with this until it is cleared.
|
||||
mastery_failure: Mutex<Option<SourceError>>,
|
||||
mastery_calls: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl FakeHistory {
|
||||
@@ -157,6 +162,9 @@ impl FakeHistory {
|
||||
fetches: Arc::default(),
|
||||
listed: Arc::default(),
|
||||
calls: Arc::default(),
|
||||
mastery: Mutex::default(),
|
||||
mastery_failure: Mutex::default(),
|
||||
mastery_calls: Arc::default(),
|
||||
}
|
||||
.with_account(account, payloads)
|
||||
}
|
||||
@@ -264,6 +272,31 @@ impl FakeHistory {
|
||||
self.calls.clone()
|
||||
}
|
||||
|
||||
/// The Mastery Points Riot lists for this Account (without any, its mastery request
|
||||
/// answers "not found").
|
||||
pub fn with_mastery(self, puuid: &str, points: &[(u32, u64)]) -> FakeHistory {
|
||||
self.set_mastery(puuid, points);
|
||||
self
|
||||
}
|
||||
|
||||
/// Replaces the Mastery Points Riot lists for this Account.
|
||||
pub fn set_mastery(&self, puuid: &str, points: &[(u32, u64)]) {
|
||||
self.mastery
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(puuid.into(), points.to_vec());
|
||||
}
|
||||
|
||||
/// Every mastery request fails with this error until `None` is set (a sync is not affected).
|
||||
pub fn fail_mastery_with(&self, error: Option<SourceError>) {
|
||||
*self.mastery_failure.lock().unwrap() = error;
|
||||
}
|
||||
|
||||
/// Mastery requests made, failed ones included. They are not counted by `call_counter`.
|
||||
pub fn mastery_counter(&self) -> Arc<AtomicUsize> {
|
||||
self.mastery_calls.clone()
|
||||
}
|
||||
|
||||
fn enter(&self) -> Result<(), SourceError> {
|
||||
self.calls.fetch_add(1, Ordering::SeqCst);
|
||||
match &*self.failure.lock().unwrap() {
|
||||
@@ -346,6 +379,23 @@ impl MatchHistorySource for FakeHistory {
|
||||
self.fetches.fetch_add(1, Ordering::SeqCst);
|
||||
Ok(raw)
|
||||
}
|
||||
|
||||
fn champion_mastery(
|
||||
&self,
|
||||
_platform: &str,
|
||||
puuid: &str,
|
||||
) -> Result<Vec<(u32, u64)>, SourceError> {
|
||||
self.mastery_calls.fetch_add(1, Ordering::SeqCst);
|
||||
if let Some(error) = &*self.mastery_failure.lock().unwrap() {
|
||||
return Err(error.clone());
|
||||
}
|
||||
self.mastery
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(puuid)
|
||||
.cloned()
|
||||
.ok_or(SourceError::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
/// Champion reference data served from memory.
|
||||
|
||||
Reference in new issue
Block a user