Skip to content

Commit 0b1c0b0

Browse files
committed
Fix slow media loading into large playlists and timelines
1 parent 7c28227 commit 0b1c0b0

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

include/xstudio/media/media_actor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ namespace media {
8888
utility::JsonTree media_list_columns_config_;
8989
utility::JsonStore human_readable_info_;
9090
utility::JsonStore media_list_columns_info_;
91+
utility::time_point creation_time_ = {utility::clock::now()};
9192
};
9293

9394
class MediaSourceActor : public caf::event_based_actor {

src/media/src/media_actor.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,8 +2075,28 @@ void MediaActor::build_media_list_info(caf::typed_response_promise<utility::Json
20752075
if (media_list_columns_info_ != *result) {
20762076
media_list_columns_info_ = *result;
20772077

2078-
mail(utility::event_atom_v, media_display_info_atom_v, media_list_columns_info_)
2079-
.send(base_.event_group());
2078+
// Media display info has changed. Emit a change event so the UI can update.
2079+
// This is needed so that the columns in the media list update when metadata
2080+
// changes.
2081+
2082+
// Temporary hack ... this event_atom, media_display_info_atom message will hit
2083+
// the SessionModelUI (via the parent playlist of this media). In SessionModelUI
2084+
// it then looks up the corresponding Media item in it's internal model data and
2085+
// updates the data for media_display_info. However, if this media item hasn't
2086+
// quite yet been added to the SessionModelUI then the lookup is very slow and
2087+
// then fails, as it falls back to a brute force recursive search for the matching
2088+
// actor_address so it looks through the whole model.
2089+
2090+
// On MediaActor creation the media_list_columns_info_ is updated a coupld of
2091+
// times as the media item (and media sources) are built so we end up here.
2092+
2093+
// Thus if we add lots of media at once (e.g. building a playlist) xstudio can
2094+
// freeze due to all these recursive searches. We therefore don't want to emit
2095+
// these events until some time after the media item has been created.
2096+
if ((utility::clock::now()-creation_time_) > std::chrono::seconds(5)) {
2097+
mail(utility::event_atom_v, media_display_info_atom_v, media_list_columns_info_)
2098+
.send(base_.event_group());
2099+
}
20802100
}
20812101
rp.deliver(*result);
20822102
}

0 commit comments

Comments
 (0)