mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-26 00:32:30 +01:00
playlist cache into memory
This commit is contained in:
@@ -1473,7 +1473,7 @@ Now you can do `nginx` configuration like
|
||||
}
|
||||
```
|
||||
When you use nginx be sure to have
|
||||
```
|
||||
```nginx
|
||||
proxy_redirect off;
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
|
||||
@@ -95,9 +95,10 @@ pub async fn m3u_get_item_for_stream_id(stream_id: u32, app_state: &AppState, ta
|
||||
{
|
||||
if let Some(playlist) = app_state.playlists.data.read().await.get(target.name.as_str()) {
|
||||
if let Some(m3u_playlist) = playlist.m3u.as_ref() {
|
||||
return Ok(m3u_playlist.query(&stream_id)
|
||||
.ok_or_else(|| str_to_io_error(&format!("Failed to read m3u item for id {stream_id}")))?
|
||||
.clone())
|
||||
if let Some(item) = m3u_playlist.query(&stream_id) {
|
||||
return Ok(item.clone());
|
||||
}
|
||||
// fall through to disk lookup on cache miss
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,24 +68,6 @@ pub async fn persist_playlist(app_config: &AppConfig, playlist: &mut [PlaylistGr
|
||||
errors.push(err);
|
||||
}
|
||||
}
|
||||
|
||||
if target.use_memory_cache {
|
||||
if let Some(playlist_storage) = playlist_state {
|
||||
match output {
|
||||
TargetOutput::Xtream(_) => {
|
||||
if let Ok(storage) = load_xtream_target_storage(app_config, target) {
|
||||
playlist_storage.cache_playlist(&target.name, PlaylistStorage::XtreamPlaylist(Box::new(storage))).await;
|
||||
}
|
||||
},
|
||||
TargetOutput::M3u(_) => {
|
||||
if let Ok(storage) = load_m3u_target_storage(app_config, target) {
|
||||
playlist_storage.cache_playlist(&target.name, PlaylistStorage::M3uPlaylist(Box::new(storage))).await;
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => errors.push(err)
|
||||
}
|
||||
@@ -96,6 +78,26 @@ pub async fn persist_playlist(app_config: &AppConfig, playlist: &mut [PlaylistGr
|
||||
}
|
||||
drop(file_lock);
|
||||
|
||||
if target.use_memory_cache {
|
||||
if let Some(playlist_storage) = playlist_state {
|
||||
for output in &target.output {
|
||||
match output {
|
||||
TargetOutput::Xtream(_) => {
|
||||
if let Ok(storage) = load_xtream_target_storage(app_config, target) {
|
||||
playlist_storage.cache_playlist(&target.name, PlaylistStorage::XtreamPlaylist(Box::new(storage))).await;
|
||||
}
|
||||
},
|
||||
TargetOutput::M3u(_) => {
|
||||
if let Ok(storage) = load_m3u_target_storage(app_config, target) {
|
||||
playlist_storage.cache_playlist(&target.name, PlaylistStorage::M3uPlaylist(Box::new(storage))).await;
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if errors.is_empty() { Ok(()) } else { Err(errors) }
|
||||
}
|
||||
|
||||
|
||||
@@ -415,10 +415,11 @@ pub async fn xtream_get_item_for_stream_id(
|
||||
xtream_cluster: Option<XtreamCluster>,
|
||||
) -> Result<(XtreamPlaylistItem, VirtualIdRecord), Error> {
|
||||
if target.use_memory_cache {
|
||||
if let Some((playlist_item, virtual_record)) =
|
||||
xtream_get_item_for_stream_id_from_memory(virtual_id, app_state, target, xtream_cluster).await? {
|
||||
if let Ok(Some((playlist_item, virtual_record))) =
|
||||
xtream_get_item_for_stream_id_from_memory(virtual_id, app_state, target, xtream_cluster).await {
|
||||
return Ok((playlist_item, virtual_record));
|
||||
}
|
||||
// fall through to disk lookup on cache miss
|
||||
}
|
||||
|
||||
let app_config: &AppConfig = &app_state.app_config;
|
||||
|
||||
Reference in New Issue
Block a user