Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asset: never reprocess assets when duplicated #1979

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/api/src/store/asset-table.ts
Expand Up @@ -3,8 +3,6 @@ import { Asset, Task, User } from "../schema/types";
import Table from "./table";
import { QueryOptions, WithID } from "./types";

const DUPLICATE_ASSETS_THRESHOLD = 15 * 60 * 1000; // 15 mins

export const taskOutputToIpfsStorage = (
out: Task["output"]["export"]["ipfs"]
): Omit<Asset["storage"]["ipfs"], "spec"> =>
Expand Down Expand Up @@ -123,14 +121,12 @@ export default class AssetTable extends Table<WithID<Asset>> {
url: string,
userId: string
): Promise<WithID<Asset>> {
const createdAfter = Date.now() - DUPLICATE_ASSETS_THRESHOLD;
const query = [
sql`asset.data->>'deleted' IS NULL`,
sql`asset.data->>'userId' = ${userId}`,
sql`asset.data->'source'->>'type' = 'url'`,
sql`asset.data->'source'->>'url' = ${url}`,
sql`asset.data->'status'->>'phase' IN ('waiting', 'processing')`,
sql`coalesce((asset.data->>'createdAt')::bigint, 0) > ${createdAfter}`,
sql`asset.data->'status'->>'phase' IN ('waiting', 'processing', 'ready')`,
];
const [assets] = await this.find(query, { limit: 1 });
return assets?.length > 0 ? assets[0] : null;
Expand Down