@@ -5,6 +5,29 @@ import { supabase, fetchCloudWatchlist, syncCloudProgress, fetchUserProfile, upd
55
66const AppContext = createContext ( null ) ;
77
8+ // Helper to minimize anime objects to prevent database/storage bloat (removes heavy characters, recommendations, description tags)
9+ function minimizeAnime ( anime ) {
10+ if ( ! anime ) return null ;
11+ return {
12+ id : anime . id ,
13+ idMal : anime . idMal || null ,
14+ title : {
15+ romaji : anime . title ?. romaji || '' ,
16+ english : anime . title ?. english || '' ,
17+ native : anime . title ?. native || ''
18+ } ,
19+ coverImage : {
20+ large : anime . coverImage ?. large || '' ,
21+ extraLarge : anime . coverImage ?. extraLarge || '' ,
22+ color : anime . coverImage ?. color || ''
23+ } ,
24+ format : anime . format || '' ,
25+ averageScore : anime . averageScore || 0 ,
26+ episodes : anime . episodes || 0 ,
27+ status : anime . status || ''
28+ } ;
29+ }
30+
831// ── Default Settings ────────────────────────────────────────────────────────
932const DEFAULT_SETTINGS = {
1033 // Player
@@ -112,18 +135,33 @@ export function AppProvider({ children }) {
112135 } catch ( _ ) { }
113136 }
114137
115- if ( finalWatchlist ) setWatchlist ( finalWatchlist ) ;
138+ if ( finalWatchlist ) {
139+ const minimizedW = { } ;
140+ Object . keys ( finalWatchlist ) . forEach ( id => {
141+ const item = finalWatchlist [ id ] ;
142+ minimizedW [ id ] = {
143+ ...item ,
144+ anime : minimizeAnime ( item ?. anime )
145+ } ;
146+ } ) ;
147+ setWatchlist ( minimizedW ) ;
148+ finalWatchlist = minimizedW ;
149+ }
116150
117151 if ( finalFavorites ) {
118152 if ( Array . isArray ( finalFavorites ) ) {
119153 // Convert legacy list/Set array of IDs to object
120154 const migrated = { } ;
121155 finalFavorites . forEach ( id => {
122- migrated [ id ] = finalWatchlist ?. [ id ] ?. anime || { id } ;
156+ migrated [ id ] = minimizeAnime ( finalWatchlist ?. [ id ] ?. anime ) || { id } ;
123157 } ) ;
124158 setFavorites ( migrated ) ;
125159 } else {
126- setFavorites ( finalFavorites ) ;
160+ const minimizedF = { } ;
161+ Object . keys ( finalFavorites ) . forEach ( id => {
162+ minimizedF [ id ] = minimizeAnime ( finalFavorites [ id ] ) ;
163+ } ) ;
164+ setFavorites ( minimizedF ) ;
127165 }
128166 }
129167
@@ -287,12 +325,21 @@ export function AppProvider({ children }) {
287325 const cloudEp = cloudItem ?. progress ?. episode || null ;
288326 const localEp = localProg ?. episode || null ;
289327
290- // If it doesn't exist in the cloud, or any of the values differ, queue for sync
328+ const cloudAnime = cloudItem ?. progress ?. anime ;
329+ const needsMinimization = cloudAnime && (
330+ cloudAnime . characters ||
331+ cloudAnime . recommendations ||
332+ cloudAnime . description ||
333+ cloudAnime . bannerImage
334+ ) ;
335+
336+ // If it doesn't exist in the cloud, any of the values differ, or it needs data minimization, queue for sync
291337 if (
292338 ! cloudItem ||
293339 cloudItem . status !== localStatus ||
294340 cloudFav !== localFav ||
295- cloudEp !== localEp
341+ cloudEp !== localEp ||
342+ needsMinimization
296343 ) {
297344 upsertRows . push ( {
298345 user_id : u . id ,
@@ -302,7 +349,7 @@ export function AppProvider({ children }) {
302349 progress : {
303350 episode : localEp ,
304351 timestamp : localProg ?. timestamp || ( cloudItem ?. progress ?. timestamp || null ) ,
305- anime : localItem ?. anime || nextFavorites [ id ] || ( cloudItem ?. progress ?. anime || { id } )
352+ anime : minimizeAnime ( localItem ?. anime || nextFavorites [ id ] || cloudAnime || { id } )
306353 } ,
307354 updated_at : new Date ( ) . toISOString ( )
308355 } ) ;
@@ -516,9 +563,10 @@ export function AppProvider({ children }) {
516563 } , [ settings . accentColor , settings . darkMode , settings . compactCards , loaded ] ) ;
517564
518565 const addToWatchlist = useCallback ( ( anime , status = 'plan_to_watch' ) => {
566+ const minimized = minimizeAnime ( anime ) ;
519567 setWatchlist ( prev => ( {
520568 ...prev ,
521- [ anime . id ] : { anime, status, addedAt : Date . now ( ) } ,
569+ [ anime . id ] : { anime : minimized , status, addedAt : Date . now ( ) } ,
522570 } ) ) ;
523571 showToast ( 'Added to My List ✓' ) ;
524572 triggerDebouncedSyncRef . current ?. ( ) ;
@@ -557,14 +605,15 @@ export function AppProvider({ children }) {
557605
558606 const toggleFavorite = useCallback ( ( animeId , anime = null ) => {
559607 let isFav = false ;
608+ const minimized = minimizeAnime ( anime ) ;
560609 setFavorites ( prev => {
561610 const next = { ...prev } ;
562611 if ( next [ animeId ] ) {
563612 delete next [ animeId ] ;
564613 showToast ( 'Removed from Favorites' ) ;
565614 isFav = false ;
566615 } else {
567- next [ animeId ] = anime || { id : animeId } ;
616+ next [ animeId ] = minimized || { id : animeId } ;
568617 showToast ( 'Added to Favorites ❤️' ) ;
569618 isFav = true ;
570619 }
@@ -586,7 +635,7 @@ export function AppProvider({ children }) {
586635 progress : {
587636 episode : ep ,
588637 timestamp : ts ,
589- anime : anime || watchlistRef . current [ animeId ] ?. anime || { id : animeId }
638+ anime : minimized || minimizeAnime ( watchlistRef . current [ animeId ] ?. anime ) || { id : animeId }
590639 } ,
591640 updated_at : new Date ( ) . toISOString ( )
592641 } , { onConflict : 'user_id,anime_id' } )
0 commit comments