Create queries for missing AI text
This commit is contained in:
parent
013acacb7b
commit
d36ae5c15a
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable quotes */
|
||||||
import {
|
import {
|
||||||
sql,
|
sql,
|
||||||
query,
|
query,
|
||||||
@ -14,7 +15,11 @@ import {
|
|||||||
import { Cameras, createCameraKey } from '@/camera';
|
import { Cameras, createCameraKey } from '@/camera';
|
||||||
import { Tags } from '@/tag';
|
import { Tags } from '@/tag';
|
||||||
import { Films } from '@/film';
|
import { Films } from '@/film';
|
||||||
import { ADMIN_SQL_DEBUG_ENABLED } from '@/app/config';
|
import {
|
||||||
|
ADMIN_SQL_DEBUG_ENABLED,
|
||||||
|
AI_TEXT_AUTO_GENERATED_FIELDS,
|
||||||
|
AI_TEXT_GENERATION_ENABLED,
|
||||||
|
} from '@/app/config';
|
||||||
import {
|
import {
|
||||||
GetPhotosOptions,
|
GetPhotosOptions,
|
||||||
getLimitAndOffsetFromOptions,
|
getLimitAndOffsetFromOptions,
|
||||||
@ -24,7 +29,11 @@ import { getWheresFromOptions } from '.';
|
|||||||
import { FocalLengths } from '@/focal';
|
import { FocalLengths } from '@/focal';
|
||||||
import { Lenses, createLensKey } from '@/lens';
|
import { Lenses, createLensKey } from '@/lens';
|
||||||
import { migrationForError } from './migration';
|
import { migrationForError } from './migration';
|
||||||
import { UPDATED_BEFORE_01, UPDATED_BEFORE_02 } from '../sync';
|
import {
|
||||||
|
SYNC_QUERY_LIMIT,
|
||||||
|
UPDATED_BEFORE_01,
|
||||||
|
UPDATED_BEFORE_02,
|
||||||
|
} from '../sync';
|
||||||
import { MAKE_FUJIFILM } from '@/platforms/fujifilm';
|
import { MAKE_FUJIFILM } from '@/platforms/fujifilm';
|
||||||
import { Recipes } from '@/recipe';
|
import { Recipes } from '@/recipe';
|
||||||
|
|
||||||
@ -568,10 +577,9 @@ export const getPhoto = async (
|
|||||||
.then(photos => photos.length > 0 ? photos[0] : undefined);
|
.then(photos => photos.length > 0 ? photos[0] : undefined);
|
||||||
}, 'getPhoto');
|
}, 'getPhoto');
|
||||||
|
|
||||||
// Outdated queries
|
// Sync queries
|
||||||
|
|
||||||
const outdatedWhereClause =
|
const outdatedWhereClause =
|
||||||
// eslint-disable-next-line quotes
|
|
||||||
`WHERE updated_at < $1 OR (updated_at < $2 AND make = $3)`;
|
`WHERE updated_at < $1 OR (updated_at < $2 AND make = $3)`;
|
||||||
|
|
||||||
const outdatedValues = [
|
const outdatedValues = [
|
||||||
@ -585,7 +593,7 @@ export const getOutdatedPhotos = () => safelyQueryPhotos(
|
|||||||
SELECT * FROM photos
|
SELECT * FROM photos
|
||||||
${outdatedWhereClause}
|
${outdatedWhereClause}
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT 1000
|
LIMIT ${SYNC_QUERY_LIMIT}
|
||||||
`,
|
`,
|
||||||
outdatedValues,
|
outdatedValues,
|
||||||
)
|
)
|
||||||
@ -603,3 +611,42 @@ export const getOutdatedPhotosCount = () => safelyQueryPhotos(
|
|||||||
.then(({ rows }) => parseInt(rows[0].count, 10)),
|
.then(({ rows }) => parseInt(rows[0].count, 10)),
|
||||||
'getOutdatedPhotosCount',
|
'getOutdatedPhotosCount',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const photosThatNeedAiTextWhereClause = (
|
||||||
|
AI_TEXT_GENERATION_ENABLED &&
|
||||||
|
AI_TEXT_AUTO_GENERATED_FIELDS.length
|
||||||
|
)
|
||||||
|
? 'WHERE ' + AI_TEXT_AUTO_GENERATED_FIELDS
|
||||||
|
.map(field => {
|
||||||
|
switch (field) {
|
||||||
|
case 'title': return `(title <> '') IS NOT TRUE`;
|
||||||
|
case 'caption': return `(caption <> '') IS NOT TRUE`;
|
||||||
|
case 'tags': return `array_length(tags, 1) = 0`;
|
||||||
|
case 'semantic': return `(semantic_description <> '') IS NOT TRUE`;
|
||||||
|
}
|
||||||
|
}).join(' OR ')
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
export const getPhotosThatNeedAiText = () => safelyQueryPhotos(
|
||||||
|
async () => photosThatNeedAiTextWhereClause
|
||||||
|
? query(`
|
||||||
|
SELECT * FROM photos
|
||||||
|
${photosThatNeedAiTextWhereClause}
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT ${SYNC_QUERY_LIMIT}
|
||||||
|
`)
|
||||||
|
.then(({ rows }) => rows.map(parsePhotoFromDb))
|
||||||
|
: [] as Photo[],
|
||||||
|
'getPhotosThatNeedAiText',
|
||||||
|
);
|
||||||
|
|
||||||
|
export const getPhotosThatNeedAiTextCount = () => safelyQueryPhotos(
|
||||||
|
async () => photosThatNeedAiTextWhereClause
|
||||||
|
? query(`
|
||||||
|
SELECT COUNT(*) FROM photos
|
||||||
|
${photosThatNeedAiTextWhereClause}
|
||||||
|
`)
|
||||||
|
.then(({ rows }) => parseInt(rows[0].count, 10))
|
||||||
|
: 0,
|
||||||
|
'getPhotosThatNeedAiTextCount',
|
||||||
|
);
|
||||||
|
|||||||
@ -2,6 +2,8 @@ import { MAKE_FUJIFILM } from '@/platforms/fujifilm';
|
|||||||
import { Photo } from '.';
|
import { Photo } from '.';
|
||||||
import { AI_TEXT_AUTO_GENERATED_FIELDS } from '@/app/config';
|
import { AI_TEXT_AUTO_GENERATED_FIELDS } from '@/app/config';
|
||||||
|
|
||||||
|
export const SYNC_QUERY_LIMIT = 1000;
|
||||||
|
|
||||||
export const UPDATED_BEFORE_01 = new Date('2024-06-16');
|
export const UPDATED_BEFORE_01 = new Date('2024-06-16');
|
||||||
// UTC 2025-02-24 05:30:00
|
// UTC 2025-02-24 05:30:00
|
||||||
export const UPDATED_BEFORE_02 = new Date(Date.UTC(2025, 1, 24, 5, 30, 0));
|
export const UPDATED_BEFORE_02 = new Date(Date.UTC(2025, 1, 24, 5, 30, 0));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user