Fix transcoder context deadline (#1313)

This commit is contained in:
Zoe Roux 2026-02-14 13:07:29 +01:00 committed by GitHub
commit 2ff12499db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 28 deletions

View File

@ -112,5 +112,6 @@ export const expo: ExpoConfig = {
],
experiments: {
typedRoutes: true,
reactCompiler: true,
},
};

View File

@ -1,6 +1,6 @@
import type { LegendListProps } from "@legendapp/list";
import { AnimatedLegendList } from "@legendapp/list/reanimated";
import { type ComponentType, type ReactElement, useRef } from "react";
import { type ComponentType, type ReactElement, useMemo, useRef } from "react";
import type { ViewStyle } from "react-native";
import { type Breakpoint, HR, useBreakpointMap } from "~/primitives";
import { type QueryIdentifier, useInfiniteFetch } from "./query";
@ -50,7 +50,7 @@ export const InfiniteFetch = <Data, Type extends string = string>({
}): JSX.Element | null => {
const { numColumns, size, gap } = useBreakpointMap(layout);
const oldItems = useRef<Data[] | undefined>(undefined);
let { items, fetchNextPage, isFetching, refetch, isRefetching } =
let { items, fetchNextPage, hasNextPage, isFetching, refetch, isRefetching } =
useInfiniteFetch(query);
if (incremental && items) oldItems.current = items;
if (incremental) items ??= oldItems.current;
@ -58,12 +58,14 @@ export const InfiniteFetch = <Data, Type extends string = string>({
if (!query.infinite)
console.warn("A non infinite query was passed to an InfiniteFetch.");
const count = items
? numColumns - (items.length % numColumns)
: placeholderCount;
const placeholders = [...Array(count === 0 ? numColumns : count)].fill(0);
const data =
isFetching || !items ? [...(items || []), ...placeholders] : items;
const data = useMemo(() => {
const count = items
? numColumns - (items.length % numColumns)
: placeholderCount;
const placeholders = [...Array(count === 0 ? numColumns : count)].fill(0);
if (!items) return placeholders;
return isFetching ? [...items, ...placeholders] : items;
}, [items, isFetching, placeholderCount, numColumns]);
return (
<AnimatedLegendList
@ -83,7 +85,11 @@ export const InfiniteFetch = <Data, Type extends string = string>({
keyExtractor={(item: any, index) => (item ? item.id : index + 1)}
horizontal={layout.layout === "horizontal"}
numColumns={layout.layout === "horizontal" ? 1 : numColumns}
onEndReached={fetchMore ? () => fetchNextPage() : undefined}
onEndReached={
fetchMore && hasNextPage && !isFetching
? () => fetchNextPage()
: undefined
}
onEndReachedThreshold={0.5}
onRefresh={layout.layout !== "horizontal" ? refetch : undefined}
refreshing={isRefetching}

View File

@ -27,7 +27,7 @@ type VideoKey struct {
quality Quality
}
func (t *Transcoder) newFileStream(ctx context.Context, path string, sha string) *FileStream {
func (t *Transcoder) newFileStream(path string, sha string) *FileStream {
ret := &FileStream{
transcoder: t,
Out: fmt.Sprintf("%s/%s", Settings.Outpath, sha),
@ -38,7 +38,7 @@ func (t *Transcoder) newFileStream(ctx context.Context, path string, sha string)
ret.ready.Add(1)
go func() {
defer ret.ready.Done()
info, err := t.metadataService.GetMetadata(ctx, path, sha)
info, err := t.metadataService.GetMetadata(context.Background(), path, sha)
ret.Info = info
if err != nil {
ret.err = err

View File

@ -167,11 +167,13 @@ func (s *MetadataService) GetMetadata(ctx context.Context, path string, sha stri
return nil, err
}
bgCtx := context.Background()
if ret.Versions.Thumbs < ThumbsVersion {
go s.ExtractThumbs(ctx, path, sha)
go s.ExtractThumbs(bgCtx, path, sha)
}
if ret.Versions.Extract < ExtractVersion {
go s.ExtractSubs(ctx, ret)
go s.ExtractSubs(bgCtx, ret)
}
if ret.Versions.Keyframes < KeyframeVersion && ret.Versions.Keyframes != 0 {
for _, video := range ret.Videos {
@ -180,14 +182,14 @@ func (s *MetadataService) GetMetadata(ctx context.Context, path string, sha stri
for _, audio := range ret.Audios {
audio.Keyframes = nil
}
tx, err := s.Database.Begin(ctx)
tx, err := s.Database.Begin(bgCtx)
if err != nil {
return nil, err
}
tx.Exec(ctx, `update gocoder.videos set keyframes = null where sha = $1`, sha)
tx.Exec(ctx, `update gocoder.audios set keyframes = null where sha = $1`, sha)
tx.Exec(ctx, `update gocoder.info set ver_keyframes = 0 where sha = $1`, sha)
err = tx.Commit(ctx)
tx.Exec(bgCtx, `update gocoder.videos set keyframes = null where sha = $1`, sha)
tx.Exec(bgCtx, `update gocoder.audios set keyframes = null where sha = $1`, sha)
tx.Exec(bgCtx, `update gocoder.info set ver_keyframes = 0 where sha = $1`, sha)
err = tx.Commit(bgCtx)
if err != nil {
fmt.Printf("error deleting old keyframes from database: %v", err)
}
@ -214,7 +216,7 @@ func (s *MetadataService) getMetadata(ctx context.Context, path string, sha stri
ret, err := pgx.CollectOneRow(rows, pgx.RowToStructByName[MediaInfo])
if errors.Is(err, pgx.ErrNoRows) || (ret.Versions.Info < InfoVersion && ret.Versions.Info != 0) {
return s.storeFreshMetadata(ctx, path, sha)
return s.storeFreshMetadata(context.Background(), path, sha)
}
if err != nil {
return nil, err

View File

@ -40,7 +40,7 @@ func getThumbVttPath(sha string) string {
}
func (s *MetadataService) GetThumbVtt(ctx context.Context, path string, sha string) (io.ReadCloser, error) {
_, err := s.ExtractThumbs(ctx, path, sha)
_, err := s.ExtractThumbs(context.Background(), path, sha)
if err != nil {
return nil, err
}
@ -54,7 +54,7 @@ func (s *MetadataService) GetThumbVtt(ctx context.Context, path string, sha stri
}
func (s *MetadataService) GetThumbSprite(ctx context.Context, path string, sha string) (io.ReadCloser, error) {
_, err := s.ExtractThumbs(ctx, path, sha)
_, err := s.ExtractThumbs(context.Background(), path, sha)
if err != nil {
return nil, err
}

View File

@ -37,9 +37,9 @@ func NewTranscoder(metadata *MetadataService) (*Transcoder, error) {
return ret, nil
}
func (t *Transcoder) getFileStream(ctx context.Context, path string, sha string) (*FileStream, error) {
func (t *Transcoder) getFileStream(path string, sha string) (*FileStream, error) {
ret, _ := t.streams.GetOrCreate(sha, func() *FileStream {
return t.newFileStream(ctx, path, sha)
return t.newFileStream(path, sha)
})
ret.ready.Wait()
if ret.err != nil {
@ -50,7 +50,7 @@ func (t *Transcoder) getFileStream(ctx context.Context, path string, sha string)
}
func (t *Transcoder) GetMaster(ctx context.Context, path string, client string, sha string) (string, error) {
stream, err := t.getFileStream(ctx, path, sha)
stream, err := t.getFileStream(path, sha)
if err != nil {
return "", err
}
@ -74,7 +74,7 @@ func (t *Transcoder) GetVideoIndex(
client string,
sha string,
) (string, error) {
stream, err := t.getFileStream(ctx, path, sha)
stream, err := t.getFileStream(path, sha)
if err != nil {
return "", err
}
@ -97,7 +97,7 @@ func (t *Transcoder) GetAudioIndex(
client string,
sha string,
) (string, error) {
stream, err := t.getFileStream(ctx, path, sha)
stream, err := t.getFileStream(path, sha)
if err != nil {
return "", err
}
@ -121,7 +121,7 @@ func (t *Transcoder) GetVideoSegment(
client string,
sha string,
) (string, error) {
stream, err := t.getFileStream(ctx, path, sha)
stream, err := t.getFileStream(path, sha)
if err != nil {
return "", err
}
@ -145,7 +145,7 @@ func (t *Transcoder) GetAudioSegment(
client string,
sha string,
) (string, error) {
stream, err := t.getFileStream(ctx, path, sha)
stream, err := t.getFileStream(path, sha)
if err != nil {
return "", err
}