Centralize insights data

This commit is contained in:
Sam Becker 2025-04-12 18:55:00 -05:00
parent b78a653b4b
commit ff6e4f6684
2 changed files with 47 additions and 46 deletions

View File

@ -8,21 +8,9 @@ import {
getUniqueTags, getUniqueTags,
} from '@/photo/db/query'; } from '@/photo/db/query';
import AdminAppInsightsClient from './AdminAppInsightsClient'; import AdminAppInsightsClient from './AdminAppInsightsClient';
import { import { getAllInsights, getGitHubMetaForCurrentApp } from '.';
APP_CONFIGURATION,
CATEGORY_VISIBILITY,
GRID_HOMEPAGE_ENABLED,
HAS_STATIC_OPTIMIZATION,
IS_META_TITLE_CONFIGURED,
IS_META_DESCRIPTION_CONFIGURED,
MATTE_PHOTOS,
} from '@/app/config';
import { getGitHubMetaForCurrentApp, getSignificantInsights } from '.';
import { getOutdatedPhotosCount } from '@/photo/db/query'; import { getOutdatedPhotosCount } from '@/photo/db/query';
const BASIC_PHOTO_INSTALLATION_COUNT = 32;
const TAG_COUNT_THRESHOLD = 12;
export default async function AdminAppInsights() { export default async function AdminAppInsights() {
const [ const [
{ count: photosCount, dateRange }, { count: photosCount, dateRange },
@ -49,43 +37,17 @@ export default async function AdminAppInsights() {
getUniqueFilms(), getUniqueFilms(),
getUniqueFocalLengths(), getUniqueFocalLengths(),
]); ]);
const { isAiTextGenerationEnabled } = APP_CONFIGURATION;
const {
forkBehind,
noAiRateLimiting,
noConfiguredDomain,
outdatedPhotos,
} = getSignificantInsights({
codeMeta,
photosCountOutdated,
});
return ( return (
<AdminAppInsightsClient <AdminAppInsightsClient
codeMeta={codeMeta} codeMeta={codeMeta}
insights={{ insights={getAllInsights({
noFork: !codeMeta?.isForkedFromBase && !codeMeta?.isBaseRepo, codeMeta,
forkBehind, photosCount,
noAi: !isAiTextGenerationEnabled, photosCountOutdated,
noAiRateLimiting, photosCountPortrait,
noConfiguredDomain, tagsCount: tags.length,
noConfiguredMeta: })}
!IS_META_TITLE_CONFIGURED ||
!IS_META_DESCRIPTION_CONFIGURED,
outdatedPhotos,
photoMatting: photosCountPortrait > 0 && !MATTE_PHOTOS,
camerasFirst: (
tags.length > TAG_COUNT_THRESHOLD &&
CATEGORY_VISIBILITY[0] !== 'cameras'
),
gridFirst: (
photosCount >= BASIC_PHOTO_INSTALLATION_COUNT &&
!GRID_HOMEPAGE_ENABLED
),
noStaticOptimization: !HAS_STATIC_OPTIMIZATION,
}}
photoStats={{ photoStats={{
photosCount, photosCount,
photosCountHidden, photosCountHidden,

View File

@ -6,10 +6,20 @@ import {
IS_VERCEL_GIT_PROVIDER_GITHUB, IS_VERCEL_GIT_PROVIDER_GITHUB,
IS_DEVELOPMENT, IS_DEVELOPMENT,
APP_CONFIGURATION, APP_CONFIGURATION,
MATTE_PHOTOS,
IS_META_DESCRIPTION_CONFIGURED,
IS_META_TITLE_CONFIGURED,
CATEGORY_VISIBILITY,
HAS_STATIC_OPTIMIZATION,
GRID_HOMEPAGE_ENABLED,
AI_TEXT_GENERATION_ENABLED,
} from '@/app/config'; } from '@/app/config';
import { PhotoDateRange } from '@/photo'; import { PhotoDateRange } from '@/photo';
import { getGitHubMeta } from '@/platforms/github'; import { getGitHubMeta } from '@/platforms/github';
const BASIC_PHOTO_INSTALLATION_COUNT = 32;
const TAG_COUNT_THRESHOLD = 12;
const AdminAppInsightCode = [ const AdminAppInsightCode = [
'noFork', 'noFork',
'forkBehind', 'forkBehind',
@ -105,3 +115,32 @@ export const indicatorStatusForSignificantInsights = (
return 'blue'; return 'blue';
} }
}; };
export const getAllInsights = ({
codeMeta,
photosCountOutdated,
photosCount,
photosCountPortrait,
tagsCount,
}: Parameters<typeof getSignificantInsights>[0] & {
photosCount: number
photosCountPortrait: number
tagsCount: number
}) => ({
...getSignificantInsights({ codeMeta, photosCountOutdated }),
noFork: !codeMeta?.isForkedFromBase && !codeMeta?.isBaseRepo,
noAi: !AI_TEXT_GENERATION_ENABLED,
noConfiguredMeta:
!IS_META_TITLE_CONFIGURED ||
!IS_META_DESCRIPTION_CONFIGURED,
photoMatting: photosCountPortrait > 0 && !MATTE_PHOTOS,
camerasFirst: (
tagsCount > TAG_COUNT_THRESHOLD &&
CATEGORY_VISIBILITY[0] !== 'cameras'
),
gridFirst: (
photosCount >= BASIC_PHOTO_INSTALLATION_COUNT &&
!GRID_HOMEPAGE_ENABLED
),
noStaticOptimization: !HAS_STATIC_OPTIMIZATION,
});