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

Remove redis from backend #1141

Merged
merged 16 commits into from
Sep 23, 2024
Merged
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
7 changes: 0 additions & 7 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ services:
- db
- dm3-storage
environment:
REDIS_URL: redis://db:6379
SIGNING_PUBLIC_KEY: ${SIGNING_PUBLIC_KEY}
SIGNING_PRIVATE_KEY: ${SIGNING_PRIVATE_KEY}
ENCRYPTION_PUBLIC_KEY: ${ENCRYPTION_PUBLIC_KEY}
Expand All @@ -36,12 +35,6 @@ services:
LOG_LEVEL: 'debug'
DATABASE_URL: ${DATABASE_URL}

db:
image: redis
restart: always
volumes:
- ${PERSISTENCE_DIRECTORY}/db/redis:/data

dm3-storage:
image: postgres:13
restart: always
Expand Down
6 changes: 0 additions & 6 deletions packages/backend/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ version: '3.6'

# The containers that compose the project
services:
db:
image: redis
restart: always
container_name: redis-backend
ports:
- '6380:6379' # map to host port 6380
postgres:
image: postgres:13
restart: always
Expand Down
6 changes: 0 additions & 6 deletions packages/backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ version: '3.6'

# The containers that compose the project
services:
db:
image: redis
restart: always
container_name: redis
ports:
- '6380:6379' # map to host port 6380
dm3-storage:
image: postgres:13
restart: always
Expand Down
27 changes: 0 additions & 27 deletions packages/backend/manual_data_migration/insertWithinDocker.sh

This file was deleted.

37 changes: 0 additions & 37 deletions packages/backend/manual_data_migration/notes.md

This file was deleted.

3 changes: 1 addition & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dotenv": "^16.0.1",
"ethers": "5.7.2",
"express": "^4.18.1",
"redis": "^4.1.0",
"prisma": "^5.10.1",
"web-push": "^3.6.7",
"yaml": "^2.1.3"
},
Expand All @@ -43,7 +43,6 @@
"@types/cors": "^2.8.17",
"@types/express": "^4.17.13",
"@types/node": "^20.3.1",
"@types/redis": "^4.0.11",
"@types/supertest": "^2.0.12",
"babel-cli": "^6.26.0",
"babel-jest": "^29.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Auth,
Authenticate,
errorHandler,
getCachedWebProvider,
getServerSecret,
Expand Down Expand Up @@ -39,7 +39,7 @@ app.use(bodyParser.json());
});
app.use('/profile', Profile(db, web3Provider, serverSecret));
app.use('/storage', Storage(db, web3Provider, serverSecret));
app.use('/auth', Auth(db, serverSecret, web3Provider));
app.use('/auth', Authenticate(db, serverSecret, web3Provider));
app.use(logError);
app.use(errorHandler);
})();
Expand Down
19 changes: 0 additions & 19 deletions packages/backend/src/persistence/account/getAccount.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/backend/src/persistence/account/index.ts

This file was deleted.

19 changes: 0 additions & 19 deletions packages/backend/src/persistence/account/setAccount.ts

This file was deleted.

64 changes: 10 additions & 54 deletions packages/backend/src/persistence/getDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
import { Account, PrismaClient } from '@prisma/client';
import { createClient } from 'redis';
import Storage from './storage';
import { ConversationRecord } from './storage/postgres/dto/ConversationRecord';
import { MessageRecord } from './storage/postgres/dto/MessageRecord';
import { IAccountDatabase } from '@dm3-org/dm3-lib-server-side';

export enum RedisPrefix {
Conversation = 'conversation:',
IncomingConversations = 'incoming.conversations:',
Sync = 'sync:',
// Account used to be called Session. The prefix still resolves to "session:" for now.
Account = 'session:',
NotificationChannel = 'notificationChannel:',
GlobalNotification = 'globalNotification:',
Otp = 'otp:',
UserStorageMigrated = 'user.storage.migrated:',
}

export async function getRedisClient() {
const url = process.env.REDIS_URL || 'redis://127.0.0.1:6380';
const socketConf = {
socket: {
tls: true,
rejectUnauthorized: false,
},
};
const client = createClient(
process.env.NODE_ENV === 'production'
? {
url,
...socketConf,
}
: { url },
);

client.on('error', (err) => {
console.error('Redis error: ' + (err as Error).message);
});

client.on('reconnecting', () => console.info('Redis reconnection'));
client.on('ready', () => console.info('Redis ready'));

await client.connect();

return client;
}

export async function getPrismaClient() {
return new PrismaClient();
}
Expand All @@ -56,28 +14,28 @@ export async function getDatabase(
const prisma = _prisma ?? (await getPrismaClient());

return {
//Session
//Account
setAccount: Storage.setAccount(prisma),
getAccount: Storage.getAccount(prisma),
hasAccount: Storage.hasAccount(prisma),
//Storage AddConversation
//AddConversation
addConversation: Storage.addConversation(prisma),
getConversationList: Storage.getConversationList(prisma),
//Storage Add Messages
//Add Messages
addMessageBatch: Storage.addMessageBatch(prisma),
//Storage Get Messages
//Get Messages
getMessagesFromStorage: Storage.getMessages(prisma),
//Storage Edit Message Batch
//Edit Message Batch
editMessageBatch: Storage.editMessageBatch(prisma),
//Storage Get Number Of Messages
//Get Number Of Messages
getNumberOfMessages: Storage.getNumberOfMessages(prisma),
//Storage Get Number Of Converations
//Get Number Of Converations
getNumberOfConverations: Storage.getNumberOfConversations(prisma),
//Storage Toggle Hide Conversation
//Toggle Hide Conversation
toggleHideConversation: Storage.toggleHideConversation(prisma),
//Storage Get Halted Messages
//Get Halted Messages
getHaltedMessages: Storage.getHaltedMessages(prisma),
//Storage Delete Halted Message
//Delete Halted Message
clearHaltedMessage: Storage.clearHaltedMessage(prisma),
};
}
Expand Down Expand Up @@ -130,5 +88,3 @@ export interface IBackendDatabase extends IAccountDatabase {
messageId: string,
) => Promise<boolean>;
}

export type Redis = Awaited<ReturnType<typeof getRedisClient>>;
15 changes: 0 additions & 15 deletions packages/backend/src/persistence/getIdEnsName.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { UserProfile } from '@dm3-org/dm3-lib-profile';
import { PrismaClient } from '@prisma/client';
import { IBackendDatabase, getDatabase, getPrismaClient } from '../getDatabase';
import {
IBackendDatabase,
getDatabase,
getPrismaClient,
} from '../../getDatabase';

const USER_NAME = '0x25A643B6e52864d0eD816F1E43c0CF49C83B8292.dm3.eth';

Expand All @@ -14,12 +18,6 @@ describe('Set Account', () => {
});

it('Creates a new Account ', async () => {
const profile: UserProfile = {
publicEncryptionKey: '',
publicSigningKey: '',
deliveryServices: [],
};

const priorSetAccount = await db.getAccount(USER_NAME);

//User has no account yet
Expand Down
11 changes: 0 additions & 11 deletions packages/backend/src/profile/getUserProfile.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/backend/src/profile/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const createDbMock = async () => {
const dbMock = {
getAccount: async (ensName: string) => Promise.resolve(accountMocked),
setAccount: async (id: string) => {},
getIdEnsName: async (ensName: string) => ensName,
};

return dbMock as any;
Expand Down Expand Up @@ -113,7 +112,6 @@ describe('Profile', () => {
setAccount: async (_: string, __: any) => {
return (_: any, __: any, ___: any) => {};
},
getIdEnsName: async (ensName: string) => ensName,
};

const app = express();
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/profile/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export default (
method: 'POST',
url: req.url,
ensName,
disableSessionCheck:
process.env.DISABLE_SESSION_CHECK === 'true',
});

// check if profile and signature are valid
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { normalizeEnsName } from '@dm3-org/dm3-lib-profile';
import { authorize } from '@dm3-org/dm3-lib-server-side';
import { authorizationMiddleware } from '@dm3-org/dm3-lib-server-side';
import { sha256, validateSchema } from '@dm3-org/dm3-lib-shared';
import cors from 'cors';
import { ethers } from 'ethers';
Expand Down Expand Up @@ -32,7 +32,7 @@ export default (
next: NextFunction,
ensName: string,
) => {
authorize(
authorizationMiddleware(
req,
res,
next,
Expand Down
4 changes: 2 additions & 2 deletions packages/delivery-service/src/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
schema,
} from '@dm3-org/dm3-lib-delivery';
import { normalizeEnsName } from '@dm3-org/dm3-lib-profile';
import { authorize } from '@dm3-org/dm3-lib-server-side';
import { authorizationMiddleware } from '@dm3-org/dm3-lib-server-side';
import { validateSchema } from '@dm3-org/dm3-lib-shared';
import cors from 'cors';
import { ethers } from 'ethers';
Expand Down Expand Up @@ -40,7 +40,7 @@ export default (
//TODO remove
router.use(cors());
router.param('ensName', async (req, res, next, ensName: string) => {
authorize(
authorizationMiddleware(
req,
res,
next,
Expand Down
Loading
Loading