diff --git a/front/app.config.ts b/front/app.config.ts index 9c42ee2e..caf856d9 100644 --- a/front/app.config.ts +++ b/front/app.config.ts @@ -112,5 +112,6 @@ export const expo: ExpoConfig = { ], experiments: { typedRoutes: true, + reactCompiler: true, }, }; diff --git a/front/src/query/fetch-infinite.tsx b/front/src/query/fetch-infinite.tsx index 748fee36..b1fb3279 100644 --- a/front/src/query/fetch-infinite.tsx +++ b/front/src/query/fetch-infinite.tsx @@ -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 = ({ }): JSX.Element | null => { const { numColumns, size, gap } = useBreakpointMap(layout); const oldItems = useRef(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 = ({ 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 ( ({ 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} diff --git a/transcoder/src/filestream.go b/transcoder/src/filestream.go index 8ce0b663..94c566e2 100644 --- a/transcoder/src/filestream.go +++ b/transcoder/src/filestream.go @@ -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 diff --git a/transcoder/src/metadata.go b/transcoder/src/metadata.go index ec09cffb..e2885698 100644 --- a/transcoder/src/metadata.go +++ b/transcoder/src/metadata.go @@ -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 diff --git a/transcoder/src/thumbnails.go b/transcoder/src/thumbnails.go index 2489cb48..ff301d26 100644 --- a/transcoder/src/thumbnails.go +++ b/transcoder/src/thumbnails.go @@ -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 } diff --git a/transcoder/src/transcoder.go b/transcoder/src/transcoder.go index 3177913e..b1aa5e28 100644 --- a/transcoder/src/transcoder.go +++ b/transcoder/src/transcoder.go @@ -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 }