Spaces:
Paused
Paused
FTA7700 commited on
Commit ·
3f07709
1
Parent(s): f42b3c5
Actually apply the timestamp-based staleness rewrite (previous attempt silently failed to anchor-match)
Browse files- api/src/handlers/admin.rs +28 -31
api/src/handlers/admin.rs
CHANGED
|
@@ -859,6 +859,17 @@ pub struct LibraryStalenessResponse {
|
|
| 859 |
/// partial rating-source availability can render under a slightly different
|
| 860 |
/// actual suffix, so this can occasionally misclassify a handful of items.
|
| 861 |
/// Scoped to posters only for v1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 862 |
pub async fn library_staleness(
|
| 863 |
State(state): State<Arc<AppState>>,
|
| 864 |
Query(query): Query<LibraryStalenessQuery>,
|
|
@@ -876,20 +887,11 @@ pub async fn library_staleness(
|
|
| 876 |
)
|
| 877 |
.await?;
|
| 878 |
|
| 879 |
-
let
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
db::get_effective_render_settings(&state.db, query.key_id, Some(&globals_parsed)).await;
|
| 883 |
-
|
| 884 |
-
let ratings_suffix = crate::services::ratings::ratings_cache_suffix(
|
| 885 |
-
&settings.ratings_order,
|
| 886 |
-
&settings.ratings_exclude,
|
| 887 |
-
settings.ratings_limit,
|
| 888 |
-
);
|
| 889 |
-
|
| 890 |
-
let mut expected_keys: Vec<String> = Vec::new();
|
| 891 |
-
let mut item_meta: Vec<(String, String, String, String)> = Vec::new();
|
| 892 |
|
|
|
|
| 893 |
for raw in &raw_items {
|
| 894 |
let id = raw
|
| 895 |
.get("_id")
|
|
@@ -909,29 +911,24 @@ pub async fn library_staleness(
|
|
| 909 |
|
| 910 |
let prefixes = crate::services::stremio_account::id_to_cache_prefixes(&id, &item_type);
|
| 911 |
if let Some(prefix) = prefixes.first() {
|
| 912 |
-
|
| 913 |
-
let suffix = crate::image::serve::settings_cache_suffix_with_ratings(
|
| 914 |
-
&settings,
|
| 915 |
-
cache::ImageType::Poster,
|
| 916 |
-
None,
|
| 917 |
-
&ratings_suffix,
|
| 918 |
-
);
|
| 919 |
-
let expected_key = format!("{id_type_str}/{id_value}{suffix}");
|
| 920 |
-
expected_keys.push(expected_key.clone());
|
| 921 |
-
item_meta.push((id.clone(), name, item_type.clone(), expected_key));
|
| 922 |
-
}
|
| 923 |
}
|
| 924 |
}
|
| 925 |
|
| 926 |
-
let
|
|
|
|
|
|
|
| 927 |
|
| 928 |
-
let items =
|
| 929 |
.into_iter()
|
| 930 |
-
.map(|(id, name, item_type,
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
|
|
|
|
|
|
|
|
|
| 935 |
})
|
| 936 |
.collect();
|
| 937 |
|
|
|
|
| 859 |
/// partial rating-source availability can render under a slightly different
|
| 860 |
/// actual suffix, so this can occasionally misclassify a handful of items.
|
| 861 |
/// Scoped to posters only for v1.
|
| 862 |
+
/// Staleness is determined by comparing timestamps, not by predicting the
|
| 863 |
+
/// rendered cache_key: predicting the exact suffix requires assuming which
|
| 864 |
+
/// rating sources will actually have data for a given title, and that
|
| 865 |
+
/// assumption is frequently wrong (e.g. Letterboxd has no ratings for TV
|
| 866 |
+
/// series at all, so any series' real suffix diverges from an "all sources
|
| 867 |
+
/// present" prediction regardless of whether it's actually up to date).
|
| 868 |
+
/// Instead: a Library item is fresh if it has an `image_meta` row (any
|
| 869 |
+
/// suffix) whose `updated_at` is newer than the API key's settings
|
| 870 |
+
/// `updated_at`. Coarser than exact-key matching (doesn't know whether a
|
| 871 |
+
/// specific setting change affects a specific title's badges), but immune
|
| 872 |
+
/// to the suffix-prediction-mismatch problem.
|
| 873 |
pub async fn library_staleness(
|
| 874 |
State(state): State<Arc<AppState>>,
|
| 875 |
Query(query): Query<LibraryStalenessQuery>,
|
|
|
|
| 887 |
)
|
| 888 |
.await?;
|
| 889 |
|
| 890 |
+
let settings_updated_at = db::get_api_key_settings_updated_at(&state.db, query.key_id)
|
| 891 |
+
.await?
|
| 892 |
+
.unwrap_or(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 893 |
|
| 894 |
+
let mut id_prefixes: Vec<(String, String, String, String)> = Vec::new();
|
| 895 |
for raw in &raw_items {
|
| 896 |
let id = raw
|
| 897 |
.get("_id")
|
|
|
|
| 911 |
|
| 912 |
let prefixes = crate::services::stremio_account::id_to_cache_prefixes(&id, &item_type);
|
| 913 |
if let Some(prefix) = prefixes.first() {
|
| 914 |
+
id_prefixes.push((id, name, item_type, prefix.clone()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 915 |
}
|
| 916 |
}
|
| 917 |
|
| 918 |
+
let last_rendered =
|
| 919 |
+
cache::max_updated_at_by_prefix(&state.db, &id_prefixes.iter().map(|(_, _, _, p)| p.clone()).collect::<Vec<_>>())
|
| 920 |
+
.await?;
|
| 921 |
|
| 922 |
+
let items = id_prefixes
|
| 923 |
.into_iter()
|
| 924 |
+
.map(|(id, name, item_type, prefix)| {
|
| 925 |
+
let rendered_at = last_rendered.get(&prefix).copied().unwrap_or(0);
|
| 926 |
+
LibraryStalenessItem {
|
| 927 |
+
stale: rendered_at < settings_updated_at,
|
| 928 |
+
id,
|
| 929 |
+
name,
|
| 930 |
+
item_type,
|
| 931 |
+
}
|
| 932 |
})
|
| 933 |
.collect();
|
| 934 |
|