Skip to content

Commit

Permalink
No cache failed playback info (#528)
Browse files Browse the repository at this point in the history
* fix: no cache failed playback info

* fix: redundant logs
  • Loading branch information
0xcadams committed Apr 3, 2024
1 parent 3f0c10a commit ca60769
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions apps/lvpr-tv/src/components/player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,31 @@ export type PlayerProps = Partial<{
}>;

const getPlaybackInfoUncached = cache(async (playbackId: string) => {
try {
const playbackInfo = await livepeer.playback.get(playbackId);
const playbackInfo = await livepeer.playback.get(playbackId);

if (!playbackInfo.playbackInfo) {
console.error("Error fetching playback info", playbackInfo);

if (!playbackInfo.playbackInfo) {
console.error("Error fetching playback info", playbackInfo);
throw new Error("Error fetching playback info");
}

return null;
}
return playbackInfo.playbackInfo;
});

return playbackInfo.playbackInfo;
const getPlaybackInfo = (id: string) => {
try {
return unstable_cache(
async () => getPlaybackInfoUncached(id),
["get-playback-info", id],
{
revalidate: 120,
},
)();
} catch (e) {
console.error(e);
return null;
}
});

const getPlaybackInfo = unstable_cache(
async (id: string) => getPlaybackInfoUncached(id),
["get-playback-info"],
{
revalidate: 120,
},
);
};

export async function PlayerWithControls(props: PlayerProps) {
if (!props.playbackId && !props.url) {
Expand Down

0 comments on commit ca60769

Please sign in to comment.