Skip to content

Commit

Permalink
feat(persistence-interface): Introduce toggle for using mongo persist…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
yousuf-haque committed Oct 12, 2023
1 parent b2bab7f commit ccca3bb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
2 changes: 2 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const snapshotHubMongoDb = new MongoClient(
);
});

export const useMongoPersistence = false; // replace with launchdarkly flag

/**
* The upstream implementation relies on @snapshot-labs/snapshot-spaces npm lib to fetch all the available spaces.
* Since this implementation is used by OpenLaw only, that dependency was removed and the spaces are loaded from the
Expand Down
12 changes: 8 additions & 4 deletions server/repositories/events-repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { postgresEventsRepository } from '../helpers/adapters/postgres';
import { Event } from '../models/event.js';
import { useMongoPersistence } from '../index.js';
import { mongoEventsRepository } from './mongo/mongo-events-repository.js';

export type EventsRepository = {
getExpiredEvents: (timestamp: number) => Promise<Event[]>;
Expand All @@ -8,17 +10,19 @@ export type EventsRepository = {
EVENT_ID: string,
space: string,
timestamp: number
) => Promise<void>,
) => Promise<void>;
insertStartedProposal: (
EVENT_ID: string,
space: string,
timestamp: number
) => Promise<void>
) => Promise<void>;
insertProposalEnd: (
EVENT_ID: string,
space: string,
timestamp: number
) => Promise<void>
) => Promise<void>;
};

export const eventsRepository: EventsRepository = postgresEventsRepository;
export const eventsRepository: EventsRepository = useMongoPersistence
? mongoEventsRepository
: postgresEventsRepository;
20 changes: 11 additions & 9 deletions server/repositories/messages-repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { postgresMessagesRepository } from '../helpers/adapters/postgres';
import { Message, MessageWithVotes } from '../models/message.js';
import { useMongoPersistence } from '../index.js';
import { mongoMessagesRepository } from './mongo/mongo-messages-repository.js';

export type MessagesRepository = {
getMessages: (spaces: string, msgType: string) => Promise<Message[]>;
Expand Down Expand Up @@ -34,7 +36,7 @@ export type MessagesRepository = {
authorIpfsHash,
relayerIpfsHash,
actionId
) => Promise<void>,
) => Promise<void>;
storeProposal: (
space,
erc712Hash,
Expand All @@ -44,20 +46,20 @@ export type MessagesRepository = {
authorIpfsHash,
relayerIpfsHash,
actionId
) => Promise<void>,
storeVote:(
) => Promise<void>;
storeVote: (
space,
erc712Hash,
token,
body,
authorIpfsHash,
relayerIpfsHash,
actionId
) => Promise<void>
sponsorDraftIfAny: (space, erc712DraftHash) => Promise<number>,
findVotesForProposals: (space, proposals) => Promise<MessageWithVotes[]>
) => Promise<void>;
sponsorDraftIfAny: (space, erc712DraftHash) => Promise<number>;
findVotesForProposals: (space, proposals) => Promise<MessageWithVotes[]>;
};



export const messagesRepository: MessagesRepository = postgresMessagesRepository;
export const messagesRepository: MessagesRepository = useMongoPersistence
? mongoMessagesRepository
: postgresMessagesRepository;
10 changes: 6 additions & 4 deletions server/repositories/offchain-proofs-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import {
OffchainProof,
postgresOffchainProofsRepository
} from '../helpers/adapters/postgres';
import { useMongoPersistence } from '../index.js';
import { mongoOffchainProofsRepository } from './mongo/mongo-offchain-proofs-repository.js';

export type OffchainProofsRepository = {
getOffchainProof: (
space: string,
merkleRoot: string
) => Promise<OffchainProof[]>;
saveOffchainProof: (
offchainProof: OffchainProof
) => Promise<void>;
saveOffchainProof: (offchainProof: OffchainProof) => Promise<void>;
};
export const offchainProofsRepository: OffchainProofsRepository = postgresOffchainProofsRepository;
export const offchainProofsRepository: OffchainProofsRepository = useMongoPersistence
? mongoOffchainProofsRepository
: postgresOffchainProofsRepository;

0 comments on commit ccca3bb

Please sign in to comment.