Filter out secondary IDs that also appear as primary IDs

This commit is contained in:
mtkennerly 2024-05-20 21:03:35 -04:00
parent 6b03d46b67
commit e0d2092c5e
No known key found for this signature in database
GPG key ID: E764BE00BE6E6408
3 changed files with 39 additions and 95 deletions

View file

@ -4,7 +4,7 @@ use crate::{
path,
resource::ResourceFile,
steam::{self, SteamCache, SteamCacheEntry},
wiki::{PathKind, WikiCache, WikiCacheEntry},
wiki::{PathKind, PrimaryIds, WikiCache, WikiCacheEntry},
Error,
};
@ -153,13 +153,15 @@ impl Manifest {
) -> Result<(), Error> {
self.0.clear();
let primary_ids = wiki_cache.primary_ids();
for (title, info) in &wiki_cache.0 {
if overrides.0.get(title).map(|x| x.omit).unwrap_or(false) {
continue;
}
let mut game = Game::default();
game.integrate_wiki(info, title);
game.integrate_wiki(info, title, &primary_ids);
for rename in &info.renamed_from {
if rename.to_lowercase() == title.to_lowercase() || self.0.contains_key(rename) {
continue;
@ -213,14 +215,24 @@ pub struct Game {
}
impl Game {
pub fn integrate_wiki(&mut self, cache: &WikiCacheEntry, title: &str) {
pub fn integrate_wiki(&mut self, cache: &WikiCacheEntry, title: &str, primary_ids: &PrimaryIds) {
self.steam = SteamMetadata { id: cache.steam };
self.gog = GogMetadata { id: cache.gog };
self.id = IdMetadata {
flatpak: None,
gog_extra: cache.gog_side.clone(),
gog_extra: cache
.gog_side
.iter()
.filter(|x| !primary_ids.gog.contains(x))
.copied()
.collect(),
lutris: cache.lutris.clone(),
steam_extra: cache.steam_side.clone(),
steam_extra: cache
.steam_side
.iter()
.filter(|x| !primary_ids.steam.contains(x))
.copied()
.collect(),
};
let paths = cache.parse_paths(title.to_string());

View file

@ -1,4 +1,4 @@
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use once_cell::sync::Lazy;
use regex::Regex;
@ -92,6 +92,12 @@ async fn is_game_article(query: &str) -> Result<bool, Error> {
Ok(false)
}
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct PrimaryIds {
pub steam: HashSet<u32>,
pub gog: HashSet<u64>,
}
impl WikiCache {
pub async fn flag_recent_changes(&mut self, meta: &mut WikiMetaCache) -> Result<(), Error> {
struct RecentChange {
@ -379,6 +385,21 @@ impl WikiCache {
Ok(())
}
pub fn primary_ids(&self) -> PrimaryIds {
let mut out = PrimaryIds::default();
for info in self.0.values() {
if let Some(id) = info.steam {
out.steam.insert(id);
}
if let Some(id) = info.gog {
out.gog.insert(id);
}
}
out
}
}
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]