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 {
|
import {
|
||||||
HIGH_DENSITY_GRID,
|
HIGH_DENSITY_GRID,
|
||||||
IS_DEVELOPMENT,
|
IS_DEVELOPMENT,
|
||||||
|
IS_PRODUCTION,
|
||||||
MATTE_PHOTOS,
|
MATTE_PHOTOS,
|
||||||
SHOW_ZOOM_CONTROLS,
|
SHOW_ZOOM_CONTROLS,
|
||||||
} from '@/app/config';
|
} from '@/app/config';
|
||||||
@ -39,6 +40,7 @@ import {
|
|||||||
SWR_KEYS,
|
SWR_KEYS,
|
||||||
SWRKey,
|
SWRKey,
|
||||||
} from '@/swr';
|
} from '@/swr';
|
||||||
|
import { warmRedisAction } from './actions';
|
||||||
|
|
||||||
export default function AppStateProvider({
|
export default function AppStateProvider({
|
||||||
children,
|
children,
|
||||||
@ -121,6 +123,10 @@ export default function AppStateProvider({
|
|||||||
setHasLoaded(true);
|
setHasLoaded(true);
|
||||||
storeTimezoneCookie();
|
storeTimezoneCookie();
|
||||||
setUserEmailEager(getAuthEmailCookie());
|
setUserEmailEager(getAuthEmailCookie());
|
||||||
|
if (IS_PRODUCTION) {
|
||||||
|
console.log('Warming redis');
|
||||||
|
warmRedisAction();
|
||||||
|
}
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
setHasLoadedWithAnimations(true);
|
setHasLoadedWithAnimations(true);
|
||||||
}, 1000);
|
}, 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 { generateText, streamText } from 'ai';
|
||||||
import { createStreamableValue } from '@ai-sdk/rsc';
|
import { createStreamableValue } from '@ai-sdk/rsc';
|
||||||
import { createOpenAI } from '@ai-sdk/openai';
|
import { createOpenAI } from '@ai-sdk/openai';
|
||||||
import { Redis } from '@upstash/redis';
|
|
||||||
import { Ratelimit } from '@upstash/ratelimit';
|
import { Ratelimit } from '@upstash/ratelimit';
|
||||||
import {
|
import { AI_CONTENT_GENERATION_ENABLED, OPENAI_BASE_URL } from '@/app/config';
|
||||||
AI_CONTENT_GENERATION_ENABLED,
|
|
||||||
HAS_REDIS_STORAGE,
|
|
||||||
OPENAI_BASE_URL,
|
|
||||||
} from '@/app/config';
|
|
||||||
import { removeBase64Prefix } from '@/utility/image';
|
import { removeBase64Prefix } from '@/utility/image';
|
||||||
import { cleanUpAiTextResponse } from '@/photo/ai';
|
import { cleanUpAiTextResponse } from '@/photo/ai';
|
||||||
|
import { redis } from '@/platforms/redis';
|
||||||
const redis = HAS_REDIS_STORAGE ? Redis.fromEnv() : undefined;
|
|
||||||
|
|
||||||
const RATE_LIMIT_IDENTIFIER = 'openai-image-query';
|
const RATE_LIMIT_IDENTIFIER = 'openai-image-query';
|
||||||
const MODEL = 'gpt-4o';
|
const MODEL = 'gpt-4o';
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
import { Redis } from '@upstash/redis';
|
import { Redis } from '@upstash/redis';
|
||||||
import { HAS_REDIS_STORAGE } from '@/app/config';
|
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
|
export const testRedisConnection = () => redis
|
||||||
? redis.get('test')
|
? redis.get(KEY_TEST)
|
||||||
: Promise.reject(false);
|
: Promise.reject(false);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user