Make queries resilient to unconfigured installations

This commit is contained in:
Sam Becker 2025-07-19 15:36:42 -05:00
parent 850af1ecdf
commit 6c73b14b85
4 changed files with 12 additions and 5 deletions

View File

@ -23,7 +23,7 @@ export async function GET() {
? getPhotosCached({
limit: MAX_PHOTOS_TO_SHOW_PER_CATEGORY,
recent: true,
})
}).catch(() => [])
: [],
getIBMPlexMono(),
getImageResponseCacheControlHeaders(),

View File

@ -1,4 +1,4 @@
import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
import { INFINITE_SCROLL_GRID_INITIAL, Photo } from '@/photo';
import { generateMetaForRecents } from '@/recents/meta';
import RecentsOverview from '@/recents/RecentsOverview';
import { getPhotosRecentsDataCached } from '@/recents/data';
@ -9,7 +9,9 @@ import { redirect } from 'next/navigation';
import { getAppText } from '@/i18n/state/server';
const getPhotosRecentsDataCachedCached = cache(() =>
getPhotosRecentsDataCached({ limit: INFINITE_SCROLL_GRID_INITIAL }));
getPhotosRecentsDataCached({ limit: INFINITE_SCROLL_GRID_INITIAL })
.catch(() => [[] as Photo[], { count: 0, dateRange: undefined}] as const),
);
export async function generateMetadata(): Promise<Metadata> {
const [

View File

@ -3,7 +3,12 @@ import { removeParamsFromUrl } from '@/utility/url';
import { Pool, QueryResult, QueryResultRow } from 'pg';
const pool = new Pool({
connectionString: removeParamsFromUrl(process.env.POSTGRES_URL, ['sslmode']),
...process.env.POSTGRES_URL && {
connectionString: removeParamsFromUrl(
process.env.POSTGRES_URL,
['sslmode'],
),
},
...POSTGRES_SSL_ENABLED && { ssl: true },
});

View File

@ -18,7 +18,7 @@ export const makeUrlAbsolute = (url?: string) => url !== undefined
.replace(/\/$/, '')
: undefined;
export const removeParamsFromUrl = (urlString = '', params: string[]) => {
export const removeParamsFromUrl = (urlString: string, params: string[]) => {
const url = new URL(urlString);
for (const param of params) {
url.searchParams.delete(param);