Skip to content

Commit

Permalink
fix: valkey client to be initialized only when needed (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne authored Oct 24, 2024
1 parent eca4510 commit dd20e78
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/adaptors/valkey.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Redis } from 'ioredis';

export const valkeyClient = new Redis('localhost:6379');
export const valkeyClient = (): Redis => {
return new Redis('localhost:6379');
};
19 changes: 15 additions & 4 deletions pkg/intermodule/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,33 @@ export const timelineModuleFacadeSymbol =
Ether.newEtherSymbol<TimelineModuleFacade>();
export const timelineModuleFacadeEther = Ether.newEther(
timelineModuleFacadeSymbol,
() => (isProduction ? timelineModuleFacade : dummyTimelineModuleFacade()),
() => timelineModuleFacade,
);

export const timelineModuleFacade = new TimelineModuleFacade(
new PushTimelineService(
accountModule,
new NoteVisibilityService(accountModule),
// ToDo: Use valkey here
new ValkeyTimelineCacheRepository(valkeyClient),
isProduction
? new ValkeyTimelineCacheRepository(valkeyClient())
: new InMemoryTimelineCacheRepository(),
// ToDo: Implement PrismaListRepository
new FetchSubscribedListService(new PrismaListRepository(prismaClient)),
new FetchSubscribedListService(
isProduction
? new PrismaListRepository(prismaClient)
: new InMemoryListRepository(),
),
),
);

/**
* Dummy timeline module.\
* **NOTE: MUST USE THIS OBJECT FOR TESTING ONLY**
* @param timelineCacheRepository
*/
export const dummyTimelineModuleFacade = (
timelineCacheRepository: InMemoryTimelineCacheRepository = new InMemoryTimelineCacheRepository(),
timelineCacheRepository: InMemoryTimelineCacheRepository,
) =>
new TimelineModuleFacade(
new PushTimelineService(
Expand Down
4 changes: 2 additions & 2 deletions pkg/timeline/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const noteVisibilityService = Cat.cat(noteVisibility).feed(
).value;

const timelineCacheRepository = isProduction
? valkeyTimelineCacheRepo(valkeyClient)
? valkeyTimelineCacheRepo(valkeyClient())
: inMemoryTimelineCacheRepo([]);

const controller = new TimelineController({
Expand Down Expand Up @@ -166,7 +166,7 @@ timeline.openapi(GetHomeTimelineRoute, async (c) => {

timeline[GetAccountTimelineRoute.method](
GetAccountTimelineRoute.path,
AuthMiddleware.handle({ forceAuthorized: false }),
AuthMiddleware.handle({ forceAuthorized: true }),
);
timeline.openapi(GetAccountTimelineRoute, async (c) => {
const actorID = Option.unwrap(c.get('accountID'));
Expand Down

0 comments on commit dd20e78

Please sign in to comment.