mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-10-15 19:45:42 -04:00
chore(cron): remove query helpers replaced by checked-at stamps
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+2
-87
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
getCastEntryForTitle,
|
||||
getLibraryTitleIds as queryGetLibraryTitleIds,
|
||||
getRefreshCandidates,
|
||||
getReturningTvShows,
|
||||
@@ -8,9 +7,6 @@ import {
|
||||
getTitleByIdForCron,
|
||||
getTitleIdsCheckedBefore,
|
||||
getTitleIdsWithStaleSeasons,
|
||||
getTitlesWithFreshRecommendations,
|
||||
getTitlesWithStaleOffers,
|
||||
getTitlesWithStaleOffersFetchedBefore,
|
||||
insertCronRunReturning,
|
||||
updateCronRunError,
|
||||
updateCronRunSuccess,
|
||||
@@ -109,17 +105,9 @@ export function getStaleNonLibraryTitlesForRefresh(staleDate: Date, limit: numbe
|
||||
return getStaleNonLibraryTitles(staleDate, limit);
|
||||
}
|
||||
|
||||
export function getStaleAvailabilityTitles(libraryIds: string[], staleDate: Date) {
|
||||
const withOffers = getTitlesWithStaleOffers(libraryIds);
|
||||
const withStaleOffers = getTitlesWithStaleOffersFetchedBefore(libraryIds, staleDate);
|
||||
return { withOffers, withStaleOffers };
|
||||
}
|
||||
|
||||
export {
|
||||
getCastEntryForTitle,
|
||||
getReturningTvShows,
|
||||
getTitleByIdForCron,
|
||||
getTitleIdsCheckedBefore,
|
||||
getTitleIdsWithStaleSeasons,
|
||||
getTitlesWithFreshRecommendations,
|
||||
};
|
||||
@@ -1,15 +1,7 @@
|
||||
import { and, eq, gte, inArray, isNotNull, isNull, lt, or, sql } from "drizzle-orm";
|
||||
import { and, eq, inArray, isNotNull, isNull, lt, or, sql } from "drizzle-orm";
|
||||
|
||||
import { db } from "../client";
|
||||
import {
|
||||
cronRuns,
|
||||
seasons,
|
||||
titleAvailability,
|
||||
titleCast,
|
||||
titleRecommendations,
|
||||
titles,
|
||||
userTitleStatus,
|
||||
} from "../schema";
|
||||
import { cronRuns, seasons, titles, userTitleStatus } from "../schema";
|
||||
|
||||
export function insertCronRunReturning(jobName: string) {
|
||||
return db
|
||||
@@ -65,37 +57,6 @@ export function getStaleNonLibraryTitles(staleDate: Date, limit: number) {
|
||||
.all();
|
||||
}
|
||||
|
||||
export function getTitlesWithStaleOffers(titleIds: string[]) {
|
||||
if (titleIds.length === 0) return new Set<string>();
|
||||
return new Set(
|
||||
db
|
||||
.select({ titleId: titleAvailability.titleId })
|
||||
.from(titleAvailability)
|
||||
.where(inArray(titleAvailability.titleId, titleIds))
|
||||
.groupBy(titleAvailability.titleId)
|
||||
.all()
|
||||
.map((r) => r.titleId),
|
||||
);
|
||||
}
|
||||
|
||||
export function getTitlesWithStaleOffersFetchedBefore(titleIds: string[], staleDate: Date) {
|
||||
if (titleIds.length === 0) return new Set<string>();
|
||||
return new Set(
|
||||
db
|
||||
.select({ titleId: titleAvailability.titleId })
|
||||
.from(titleAvailability)
|
||||
.where(
|
||||
and(
|
||||
inArray(titleAvailability.titleId, titleIds),
|
||||
lt(titleAvailability.lastFetchedAt, staleDate),
|
||||
),
|
||||
)
|
||||
.groupBy(titleAvailability.titleId)
|
||||
.all()
|
||||
.map((r) => r.titleId),
|
||||
);
|
||||
}
|
||||
|
||||
export function getReturningTvShows() {
|
||||
const returningStatuses = ["Returning Series", "In Production"];
|
||||
return db
|
||||
@@ -133,10 +94,6 @@ export function getTitleByIdForCron(titleId: string) {
|
||||
return db.select().from(titles).where(eq(titles.id, titleId)).get();
|
||||
}
|
||||
|
||||
export function getCastEntryForTitle(titleId: string) {
|
||||
return db.select().from(titleCast).where(eq(titleCast.titleId, titleId)).limit(1).get();
|
||||
}
|
||||
|
||||
export function deleteOldCronRuns(beforeDate: Date): number {
|
||||
return db
|
||||
.delete(cronRuns)
|
||||
@@ -145,29 +102,6 @@ export function deleteOldCronRuns(beforeDate: Date): number {
|
||||
.all().length;
|
||||
}
|
||||
|
||||
export function getTitlesWithFreshRecommendations(
|
||||
titleIds: string[],
|
||||
sinceDate: Date,
|
||||
): Set<string> {
|
||||
if (titleIds.length === 0) return new Set();
|
||||
|
||||
return new Set(
|
||||
db
|
||||
.select({ titleId: titleRecommendations.titleId })
|
||||
.from(titleRecommendations)
|
||||
.where(
|
||||
and(
|
||||
inArray(titleRecommendations.titleId, titleIds),
|
||||
// All recs for a title share the same lastFetchedAt, so any row suffices
|
||||
gte(titleRecommendations.lastFetchedAt, sinceDate),
|
||||
),
|
||||
)
|
||||
.groupBy(titleRecommendations.titleId)
|
||||
.all()
|
||||
.map((r) => r.titleId),
|
||||
);
|
||||
}
|
||||
|
||||
type CheckedAtColumn = "availabilityCheckedAt" | "recommendationsCheckedAt" | "creditsCheckedAt";
|
||||
|
||||
/** Ids (from `titleIds`) whose `column` is null or older than `staleDate`. */
|
||||
|
||||
@@ -384,13 +384,6 @@ export function deleteAllEpisodeWatchesForTitle(userId: string, titleId: string)
|
||||
|
||||
type WatchSource = "manual" | "import" | "plex" | "jellyfin" | "emby";
|
||||
|
||||
export interface WatchHistoryCursor {
|
||||
/** watchedAt in epoch ms */
|
||||
t: number;
|
||||
/** watch row id */
|
||||
i: string;
|
||||
}
|
||||
|
||||
export interface WatchHistoryQueryOptions {
|
||||
limit: number;
|
||||
source?: WatchSource;
|
||||
|
||||
Reference in new issue
Block a user