Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-2536 Introduce toggle for using mongo persistence #95

Open
wants to merge 1 commit into
base: yousuf-haque/ENG-2537-implement-mongo-persistence-apis
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has me thinking. Since gcf-snapshot-analytics uses the Postgres database directly to write queries against can we write to both repositories for a little while until I can get the queries migrated?

? 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;