Warm redis store once per client session
This commit is contained in:
parent
f7de56a7b9
commit
200f73a5ca
@ -15,6 +15,7 @@ import useSWR, { useSWRConfig } from 'swr';
|
||||
import {
|
||||
HIGH_DENSITY_GRID,
|
||||
IS_DEVELOPMENT,
|
||||
IS_PRODUCTION,
|
||||
MATTE_PHOTOS,
|
||||
SHOW_ZOOM_CONTROLS,
|
||||
} from '@/app/config';
|
||||
@ -39,6 +40,7 @@ import {
|
||||
SWR_KEYS,
|
||||
SWRKey,
|
||||
} from '@/swr';
|
||||
import { warmRedisAction } from './actions';
|
||||
|
||||
export default function AppStateProvider({
|
||||
children,
|
||||
@ -121,6 +123,10 @@ export default function AppStateProvider({
|
||||
setHasLoaded(true);
|
||||
storeTimezoneCookie();
|
||||
setUserEmailEager(getAuthEmailCookie());
|
||||
if (IS_PRODUCTION) {
|
||||
console.log('Warming redis');
|
||||
warmRedisAction();
|
||||
}
|
||||
const timeout = setTimeout(() => {
|
||||
setHasLoadedWithAnimations(true);
|
||||
}, 1000);
|
||||
|
||||
5
src/app/actions.ts
Normal file
5
src/app/actions.ts
Normal file
@ -0,0 +1,5 @@
|
||||
'use server';
|
||||
|
||||
import { warmRedisConnection } from '@/platforms/redis';
|
||||
|
||||
export const warmRedisAction = async () => warmRedisConnection();
|
||||
@ -1,17 +1,11 @@
|
||||
import { generateText, streamText } from 'ai';
|
||||
import { createStreamableValue } from '@ai-sdk/rsc';
|
||||
import { createOpenAI } from '@ai-sdk/openai';
|
||||
import { Redis } from '@upstash/redis';
|
||||
import { Ratelimit } from '@upstash/ratelimit';
|
||||
import {
|
||||
AI_CONTENT_GENERATION_ENABLED,
|
||||
HAS_REDIS_STORAGE,
|
||||
OPENAI_BASE_URL,
|
||||
} from '@/app/config';
|
||||
import { AI_CONTENT_GENERATION_ENABLED, OPENAI_BASE_URL } from '@/app/config';
|
||||
import { removeBase64Prefix } from '@/utility/image';
|
||||
import { cleanUpAiTextResponse } from '@/photo/ai';
|
||||
|
||||
const redis = HAS_REDIS_STORAGE ? Redis.fromEnv() : undefined;
|
||||
import { redis } from '@/platforms/redis';
|
||||
|
||||
const RATE_LIMIT_IDENTIFIER = 'openai-image-query';
|
||||
const MODEL = 'gpt-4o';
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import { Redis } from '@upstash/redis';
|
||||
import { HAS_REDIS_STORAGE } from '@/app/config';
|
||||
|
||||
const redis = HAS_REDIS_STORAGE ? Redis.fromEnv() : undefined;
|
||||
const KEY_TEST = 'test';
|
||||
|
||||
export const redis = HAS_REDIS_STORAGE ? Redis.fromEnv() : undefined;
|
||||
|
||||
export const warmRedisConnection = () => {
|
||||
if (redis) { redis.get(KEY_TEST); }
|
||||
};
|
||||
|
||||
export const testRedisConnection = () => redis
|
||||
? redis.get('test')
|
||||
? redis.get(KEY_TEST)
|
||||
: Promise.reject(false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user