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,
} from '@/photo/db/query';
import AdminAppInsightsClient from './AdminAppInsightsClient';
import {
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 { getAllInsights, getGitHubMetaForCurrentApp } from '.';
import { getOutdatedPhotosCount } from '@/photo/db/query';
const BASIC_PHOTO_INSTALLATION_COUNT = 32;
const TAG_COUNT_THRESHOLD = 12;
export default async function AdminAppInsights() {
const [
{ count: photosCount, dateRange },
@ -49,43 +37,17 @@ export default async function AdminAppInsights() {
getUniqueFilms(),
getUniqueFocalLengths(),
]);
const { isAiTextGenerationEnabled } = APP_CONFIGURATION;
const {
forkBehind,
noAiRateLimiting,
noConfiguredDomain,
outdatedPhotos,
} = getSignificantInsights({
codeMeta,
photosCountOutdated,
});
return (
<AdminAppInsightsClient
codeMeta={codeMeta}
insights={{
noFork: !codeMeta?.isForkedFromBase && !codeMeta?.isBaseRepo,
forkBehind,
noAi: !isAiTextGenerationEnabled,
noAiRateLimiting,
noConfiguredDomain,
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,
}}
insights={getAllInsights({
codeMeta,
photosCount,
photosCountOutdated,
photosCountPortrait,
tagsCount: tags.length,
})}
photoStats={{
photosCount,
photosCountHidden,

View File

@ -6,10 +6,20 @@ import {
IS_VERCEL_GIT_PROVIDER_GITHUB,
IS_DEVELOPMENT,
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';
import { PhotoDateRange } from '@/photo';
import { getGitHubMeta } from '@/platforms/github';
const BASIC_PHOTO_INSTALLATION_COUNT = 32;
const TAG_COUNT_THRESHOLD = 12;
const AdminAppInsightCode = [
'noFork',
'forkBehind',
@ -105,3 +115,32 @@ export const indicatorStatusForSignificantInsights = (
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,
});