From 03ac8be368182a121fd4c3326e668309e4bf24f8 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Thu, 13 Feb 2025 23:03:15 -0600 Subject: [PATCH] Refine app insight rules --- src/admin/github/index.ts | 27 ++++++++++-- src/admin/insights/AdminAppInsights.tsx | 31 ++++++++------ src/admin/insights/AdminAppInsightsClient.tsx | 41 +++++++++++++++---- src/admin/insights/index.ts | 9 ++-- src/app-core/config.ts | 11 ++--- src/app/layout.tsx | 19 ++++----- src/components/ScoreCardRow.tsx | 2 +- src/photo/db/index.ts | 6 +++ 8 files changed, 100 insertions(+), 46 deletions(-) diff --git a/src/admin/github/index.ts b/src/admin/github/index.ts index fae49ffd..3f9d38e3 100644 --- a/src/admin/github/index.ts +++ b/src/admin/github/index.ts @@ -22,11 +22,23 @@ interface RepoParams { // Website urls +export const getGitHubOwnerUrl = ({ + owner = TEMPLATE_REPO_OWNER, +}: RepoParams = {}) => + `https://github.com/${owner}`; + export const getGitHubRepoUrl = ({ owner = TEMPLATE_REPO_OWNER, repo = TEMPLATE_REPO_NAME, }: RepoParams = {}) => - `https://github.com/${owner}/${repo}`; + `${getGitHubOwnerUrl({ owner })}/${repo}`; + +export const getGitHubBranchUrl = ({ + owner = TEMPLATE_REPO_OWNER, + repo = TEMPLATE_REPO_NAME, + branch = DEFAULT_BRANCH, +}: RepoParams = {}) => + `${getGitHubRepoUrl({ owner, repo })}/tree/${branch}`; export const getGitHubCompareUrl = ({ owner, @@ -112,7 +124,10 @@ export const getGitHubPublicFork = async ( }; const getGitHubMeta = async (params: RepoParams) => { - const url = getGitHubRepoUrl(params); + const urlOwner = getGitHubOwnerUrl(params); + const urlRepo = getGitHubRepoUrl(params); + const urlBranch = getGitHubBranchUrl(params); + const isBaseRepo = isRepoBaseRepo(params); const [ @@ -145,7 +160,9 @@ const getGitHubMeta = async (params: RepoParams) => { return { ...params, - url, + urlOwner, + urlRepo, + urlBranch, isForkedFromBase, isBaseRepo, behindBy, @@ -162,7 +179,9 @@ export const getGitHubMetaWithFallback = (params: RepoParams) => console.error('Error retrieving GitHub meta', { params, error: e }); return { ...params, - url: undefined, + urlOwner: undefined, + urlRepo: undefined, + urlBranch: undefined, isForkedFromBase: false, isBaseRepo: undefined, behindBy: undefined, diff --git a/src/admin/insights/AdminAppInsights.tsx b/src/admin/insights/AdminAppInsights.tsx index d56eb6fe..7c75ee7d 100644 --- a/src/admin/insights/AdminAppInsights.tsx +++ b/src/admin/insights/AdminAppInsights.tsx @@ -8,7 +8,11 @@ import { import AdminAppInsightsClient from './AdminAppInsightsClient'; import { APP_CONFIGURATION, + GRID_HOMEPAGE_ENABLED, + HAS_STATIC_OPTIMIZATION, + IS_DEVELOPMENT, IS_VERCEL_GIT_PROVIDER_GITHUB, + MATTE_PHOTOS, VERCEL_GIT_BRANCH, VERCEL_GIT_COMMIT_SHA, VERCEL_GIT_REPO_OWNER, @@ -23,8 +27,9 @@ const commit = VERCEL_GIT_COMMIT_SHA; export default async function AdminAppInsights() { const [ - { count, dateRange }, - { count: countHidden }, + { count: photosCount, dateRange }, + { count: photosCountHidden }, + { count: photosCountPortrait }, tags, cameras, filmSimulations, @@ -32,6 +37,7 @@ export default async function AdminAppInsights() { ] = await Promise.all([ getPhotosMeta({ hidden: 'include' }), getPhotosMeta({ hidden: 'only' }), + getPhotosMeta({ maximumAspectRatio: 0.9 }), getUniqueTags(), getUniqueCameras(), getUniqueFilmSimulations(), @@ -43,7 +49,7 @@ export default async function AdminAppInsights() { hasVercelBlobStorage, } = APP_CONFIGURATION; - const codeMeta = IS_VERCEL_GIT_PROVIDER_GITHUB + const codeMeta = IS_VERCEL_GIT_PROVIDER_GITHUB || IS_DEVELOPMENT ? await getGitHubMetaWithFallback({ owner, repo, @@ -56,23 +62,24 @@ export default async function AdminAppInsights() { 0 && !MATTE_PHOTOS, + gridFirst: photosCount > 32 && !GRID_HOMEPAGE_ENABLED, + noStaticOptimization: !HAS_STATIC_OPTIMIZATION, }} photoStats={{ - photosCount: count, - photosCountHidden: countHidden, + photosCount, + photosCountHidden, tagsCount: tags.length, camerasCount: cameras.length, filmSimulationsCount: filmSimulations.length, lensesCount: lenses.length, dateRange, }} - debug + debug={IS_DEVELOPMENT} /> ); } diff --git a/src/admin/insights/AdminAppInsightsClient.tsx b/src/admin/insights/AdminAppInsightsClient.tsx index 62e73176..38a0b732 100644 --- a/src/admin/insights/AdminAppInsightsClient.tsx +++ b/src/admin/insights/AdminAppInsightsClient.tsx @@ -16,7 +16,7 @@ import { import { MdLightbulbOutline } from 'react-icons/md'; import { PiWarningBold } from 'react-icons/pi'; import { TbCone } from 'react-icons/tb'; -import { getGitHubMetaWithFallback } from './github'; +import { getGitHubMetaWithFallback } from '../github'; import { BiGitBranch, BiGitCommit, BiLogoGithub } from 'react-icons/bi'; import { TEMPLATE_REPO_BRANCH, @@ -24,13 +24,17 @@ import { TEMPLATE_REPO_NAME, VERCEL_GIT_COMMIT_SHA_SHORT, } from '@/app-core/config'; -import { AdminAppInsight } from './insights'; +import { AdminAppInsight } from '.'; const DEBUG_COMMIT_SHA = '4cd29ed'; const DEBUG_COMMIT_MESSAGE = 'Long commit message for debugging purposes'; export default function AdminAppInsightsClient({ codeMeta, + recommendations: { + noAi, + noAiRateLimiting, + }, photoStats: { photosCount, photosCountHidden, @@ -68,20 +72,33 @@ export default function AdminAppInsightsClient({ className="flex flex-wrap gap-x-4 gap-y-1 overflow-auto" >
-
{codeMeta?.owner ?? TEMPLATE_REPO_OWNER}
+ + {codeMeta?.owner ?? TEMPLATE_REPO_OWNER} +
/
-
{codeMeta?.repo ?? TEMPLATE_REPO_NAME}
+ + {codeMeta?.repo ?? TEMPLATE_REPO_NAME} +
-
+ {codeMeta?.branch ?? TEMPLATE_REPO_BRANCH} -
+
} /> } icon={} content={
@@ -106,7 +123,7 @@ export default function AdminAppInsightsClient({ } - + />} + {(noAi || debug) && } + content="Enable AI text generation to improve photo descriptions" + // eslint-disable-next-line max-len + additionalContent="Create Vercel KV store and link it to this project in order to enable rate limiting." + />} } // eslint-disable-next-line max-len diff --git a/src/admin/insights/index.ts b/src/admin/insights/index.ts index f92111a4..156b5bcf 100644 --- a/src/admin/insights/index.ts +++ b/src/admin/insights/index.ts @@ -1,7 +1,8 @@ export type AdminAppInsight = - 'fork' | + 'noFork' | 'forkBehind' | - 'ai' | - 'aiRateLimiting' | + 'noAi' | + 'noAiRateLimiting' | 'photoMatting' | - 'gridFirst'; + 'gridFirst' | + 'noStaticOptimization'; diff --git a/src/app-core/config.ts b/src/app-core/config.ts index 03afd8d0..5dfe1a30 100644 --- a/src/app-core/config.ts +++ b/src/app-core/config.ts @@ -175,6 +175,11 @@ export const STATICALLY_OPTIMIZED_PHOTO_CATEGORIES = process.env.NEXT_PUBLIC_STATICALLY_OPTIMIZE_PHOTO_CATEGORIES === '1'; export const STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES = process.env.NEXT_PUBLIC_STATICALLY_OPTIMIZE_PHOTO_CATEGORY_OG_IMAGES === '1'; +export const HAS_STATIC_OPTIMIZATION = + STATICALLY_OPTIMIZED_PHOTOS || + STATICALLY_OPTIMIZED_PHOTO_OG_IMAGES || + STATICALLY_OPTIMIZED_PHOTO_CATEGORIES || + STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES; export const PRESERVE_ORIGINAL_UPLOADS = process.env.NEXT_PUBLIC_PRESERVE_ORIGINAL_UPLOADS === '1' || // Legacy environment variable name @@ -285,11 +290,7 @@ export const APP_CONFIGURATION = { hasAiTextAutoGeneratedFields: Boolean(process.env.AI_TEXT_AUTO_GENERATED_FIELDS), // Performance - isStaticallyOptimized: ( - STATICALLY_OPTIMIZED_PHOTOS || - STATICALLY_OPTIMIZED_PHOTO_OG_IMAGES || - STATICALLY_OPTIMIZED_PHOTO_CATEGORIES - ), + isStaticallyOptimized: HAS_STATIC_OPTIMIZATION, arePhotosStaticallyOptimized: STATICALLY_OPTIMIZED_PHOTOS, arePhotoOGImagesStaticallyOptimized: STATICALLY_OPTIMIZED_PHOTO_OG_IMAGES, arePhotoCategoriesStaticallyOptimized: STATICALLY_OPTIMIZED_PHOTO_CATEGORIES, diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 2e0d809b..26171370 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -72,11 +72,8 @@ export default function RootLayout({ > - - + +
-
-
- - - - + + + + + +
diff --git a/src/components/ScoreCardRow.tsx b/src/components/ScoreCardRow.tsx index 7e4c40da..addc539b 100644 --- a/src/components/ScoreCardRow.tsx +++ b/src/components/ScoreCardRow.tsx @@ -32,7 +32,7 @@ export default function ScoreCardRow({ {content}
{isExpanded && -
+
{additionalContent}
}
diff --git a/src/photo/db/index.ts b/src/photo/db/index.ts index 72ba97a8..6b0fe754 100644 --- a/src/photo/db/index.ts +++ b/src/photo/db/index.ts @@ -17,6 +17,7 @@ export type GetPhotosOptions = { limit?: number offset?: number query?: string + maximumAspectRatio?: number takenBefore?: Date takenAfterInclusive?: Date updatedBefore?: Date @@ -36,6 +37,7 @@ export const getWheresFromOptions = ( takenAfterInclusive, updatedBefore, query, + maximumAspectRatio, tag, camera, lens, @@ -73,6 +75,10 @@ export const getWheresFromOptions = ( wheres.push(`CONCAT(title, ' ', caption, ' ', semantic_description) ILIKE $${valuesIndex++}`); wheresValues.push(`%${query.toLocaleLowerCase()}%`); } + if (maximumAspectRatio) { + wheres.push(`aspect_ratio <= $${valuesIndex++}`); + wheresValues.push(maximumAspectRatio); + } if (tag) { wheres.push(`$${valuesIndex++}=ANY(tags)`); wheresValues.push(tag);