[vlc-commits] [Git][videolan/vlc][master] macosx: Cancel failed cache updates cleanly in library model and tests

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Wed Nov 18 13:49:26 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
c48b46e9 by Claudio Cambra at 2026-11-18T14:39:35+01:00
macosx: Cancel failed cache updates cleanly in library model and tests

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


4 changed files:

- modules/gui/macosx/library/VLCLibraryModel.m
- modules/gui/macosx/tests/VLCLibraryModelConcurrencyTest.m
- modules/gui/macosx/tests/VLCLibraryModelTestSupport.h
- modules/gui/macosx/tests/VLCLibraryModelTestSupport.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryModel.m
=====================================
@@ -413,6 +413,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 {
     if (_p_eventCallback) {
         vlc_ml_event_unregister_callback(_p_mediaLibrary, _p_eventCallback);
+        _p_eventCallback = NULL;
     }
 }
 
@@ -651,6 +652,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
         NSDictionary<NSNumber *, NSNumber *> * const showIDs = [self showIDsByEpisodeIDForShows:shows];
         if (showIDs == nil) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedListOfShows)];
             return;
         }
         [self performCacheWriteForGeneration:generation
@@ -796,6 +798,15 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     }
 }
 
+- (void)cancelCacheUpdateForToken:(NSObject *)token getter:(SEL)getter
+{
+    @synchronized (_cacheUpdateTokens) {
+        if ([self isCurrentCacheUpdate:token forGetter:getter]) {
+            [self invalidateCacheUpdateForGetter:getter];
+        }
+    }
+}
+
 - (void)performCacheMutationForGetters:(const SEL *)getters
                                  count:(NSUInteger)count
                                  block:(dispatch_block_t)block
@@ -880,6 +891,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
         vlc_ml_media_list_t * const p_media_list = vlc_ml_list_audio_media(self->_p_mediaLibrary, &queryParams);
         NSArray * const mediaArray = [NSArray arrayFromVlcMediaList:p_media_list];
         if (mediaArray == nil) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedAudioMedia)];
             return;
         }
         vlc_ml_media_list_release(p_media_list);
@@ -1124,6 +1136,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
         queryParameters.psz_pattern = filterString.length > 0 ? filterString.UTF8String : NULL;
         vlc_ml_media_list_t *p_media_list = vlc_ml_list_video_media(self->_p_mediaLibrary, &queryParameters);
         if (p_media_list == NULL) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedVideoMedia)];
             return;
         }
         NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:p_media_list->i_nb_items];
@@ -1254,6 +1267,9 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 
         NSArray * const mediaArray = [NSArray arrayFromVlcMediaList:p_media_list];
         if (mediaArray == nil) {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                completionHandler(nil);
+            });
             return;
         }
         vlc_ml_media_list_release(p_media_list);
@@ -1280,6 +1296,10 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     [self getListOfRecentMediaOfType:VLC_ML_MEDIA_TYPE_VIDEO
                       withCountLimit:_recentMediaLimit
                       withCompletion:^(NSArray * const mediaArray) {
+        if (mediaArray == nil) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedRecentMedia)];
+            return;
+        }
         [self performCacheWriteForGeneration:generation
                                        token:token
                                       getter:@selector(cachedRecentMedia)
@@ -1324,6 +1344,10 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     [self getListOfRecentMediaOfType:VLC_ML_MEDIA_TYPE_AUDIO
                       withCountLimit:_recentAudioMediaLimit
                       withCompletion:^(NSArray * const mediaArray) {
+        if (mediaArray == nil) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedRecentAudioMedia)];
+            return;
+        }
         [self performCacheWriteForGeneration:generation
                                        token:token
                                       getter:@selector(cachedRecentAudioMedia)
@@ -1394,11 +1418,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
             : vlc_ml_list_video_media(self->_p_mediaLibrary, &queryParams);
         NSArray * const media = [NSArray arrayFromVlcMediaList:mediaList];
         if (media == nil) {
-            @synchronized (self->_cacheUpdateTokens) {
-                if ([self isCurrentCacheUpdate:token forGetter:getter]) {
-                    [self invalidateCacheUpdateForGetter:getter];
-                }
-            }
+            [self cancelCacheUpdateForToken:token getter:getter];
             return;
         }
         vlc_ml_media_list_release(mediaList);
@@ -1558,6 +1578,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
         vlc_ml_show_list_t * const p_show_list = vlc_ml_list_shows(self->_p_mediaLibrary, NULL);
         if (p_show_list == NULL) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedListOfShows)];
             return;
         }
         const size_t itemCount = p_show_list->i_nb_items;
@@ -1572,6 +1593,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
         vlc_ml_show_list_release(p_show_list);
         NSDictionary<NSNumber *, NSNumber *> * const showIDs = [self showIDsByEpisodeIDForShows:mutableArray];
         if (showIDs == nil) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedListOfShows)];
             return;
         }
         [self performCacheWriteForGeneration:generation
@@ -1674,6 +1696,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
         vlc_ml_media_list_t * const p_movie_list = vlc_ml_list_movies(self->_p_mediaLibrary, NULL);
         if (p_movie_list == NULL) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedListOfMovies)];
             return;
         }
         const size_t itemCount = p_movie_list->i_nb_items;
@@ -1779,6 +1802,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
         vlc_ml_group_list_t * const p_group_list =
             vlc_ml_list_groups(self->_p_mediaLibrary, &queryParams);
         if (p_group_list == NULL) {
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedListOfGroups)];
             return;
         }
         const size_t itemCount = p_group_list->i_nb_items;
@@ -1868,6 +1892,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
         vlc_ml_folder_list_t *pp_entrypoints = vlc_ml_list_entry_points(self->_p_mediaLibrary, NULL);
         if (pp_entrypoints == NULL) {
             msg_Err(getIntf(), "failed to retrieve list of monitored library folders");
+            [self cancelCacheUpdateForToken:token getter:@selector(cachedListOfMonitoredFolders)];
             return;
         }
 


=====================================
modules/gui/macosx/tests/VLCLibraryModelConcurrencyTest.m
=====================================
@@ -58,6 +58,7 @@ typedef NS_ENUM(NSUInteger, VLCLibraryModelSupersedingAction) {
 {
     // XCTest runs the registered gate/observer teardown blocks first.
     if (self.fixture != nil) {
+        [self.fixture.model applicationWillTerminate:nil];
         XCTestExpectation * const finished = [self expectationWithDescription:@"Native reads finished before library shutdown"];
         [self.fixture.model finishPendingQueriesWithCompletion:^{
             [finished fulfill];


=====================================
modules/gui/macosx/tests/VLCLibraryModelTestSupport.h
=====================================
@@ -66,6 +66,8 @@
                   withBlock:(NSArray *(^)(void))block;
 - (NSObject *)beginCacheUpdateForGetter:(SEL)getter
                              generation:(NSUInteger *)generation;
+- (void)cancelCacheUpdateForToken:(NSObject *)token
+                           getter:(SEL)getter;
 - (void)performCacheWriteForGeneration:(NSUInteger)generation
                                  token:(NSObject *)token
                                 getter:(SEL)getter


=====================================
modules/gui/macosx/tests/VLCLibraryModelTestSupport.m
=====================================
@@ -440,6 +440,19 @@ VLCMediaLibraryMediaItem *VLCLibraryModelTestMediaItem(vlc_ml_media_type_t type,
     return token;
 }
 
+- (void)cancelCacheUpdateForToken:(NSObject *)token
+                           getter:(SEL)getter
+{
+    [super cancelCacheUpdateForToken:token getter:getter];
+    @synchronized (self) {
+        [_pendingQueries removeObject:token];
+        if (_pendingQueries.count == 0 && _queriesFinished != nil) {
+            dispatch_async(dispatch_get_main_queue(), _queriesFinished);
+            _queriesFinished = nil;
+        }
+    }
+}
+
 - (NSUInteger)queryCountForGetter:(SEL)getter
 {
     @synchronized (self) {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/c48b46e97f99abbbca622110684da65ab2a22688

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/c48b46e97f99abbbca622110684da65ab2a22688
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list