Skip to content

Commit dd160fb

Browse files
committed
refactor: improve usage tracking
- Updating user handling to use numeric ID instead of username - Implementing more efficient Redis-based user usage tracking - Adjusting node and user synchronization mechanisms - Improving error handling and performance in various queues - Adding support for dynamic worker concurrency
1 parent ec83049 commit dd160fb

File tree

55 files changed

+651
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+651
-141
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN if [ "$BRANCH" = "dev" ]; then \
2424
mkdir -p frontend_crowdin_temp/dist; \
2525
fi
2626

27-
FROM node:22.21-alpine AS backend-build
27+
FROM node:24.11-alpine AS backend-build
2828
WORKDIR /opt/app
2929

3030
# RUN apk add python3 python3-dev build-base pkgconfig libunwind-dev
@@ -49,7 +49,7 @@ RUN npm cache clean --force
4949

5050
RUN npm prune --omit=dev
5151

52-
FROM node:22.21-alpine
52+
FROM node:24.11-alpine
5353
WORKDIR /opt/app
5454

5555
ARG BRANCH=main

ecosystem.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ module.exports = {
4040
name: 'remnawave-jobs',
4141
script: 'dist/src/bin/processors/processors.js',
4242
watch: false,
43-
instances: 1,
44-
exec_mode: 'fork',
43+
instances: process.env.WORKER_INSTANCES || 1,
44+
exec_mode: 'cluster',
4545
merge_logs: true,
4646
instance_var: 'INSTANCE_ID',
4747
env_development: {

libs/contract/api/controllers/users.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const USERS_ROUTES = {
1717
REVOKE_SUBSCRIPTION: (uuid: string) => `${uuid}/${USERS_ACTIONS_ROUTE}/revoke`,
1818
},
1919
GET_BY: {
20+
ID: (id: string) => `by-id/${id}`,
2021
SHORT_UUID: (shortUuid: string) => `by-short-uuid/${shortUuid}`,
2122
USERNAME: (username: string) => `by-username/${username}`,
2223
SUBSCRIPTION_UUID: (subscriptionUuid: string) => `by-subscription-uuid/${subscriptionUuid}`,

libs/contract/api/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export const REST_API = {
121121
},
122122

123123
GET_BY: {
124+
ID: (id: string) =>
125+
`${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.GET_BY.ID(id)}`,
124126
SHORT_UUID: (shortUuid: string) =>
125127
`${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.GET_BY.SHORT_UUID(
126128
shortUuid,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { z } from 'zod';
2+
3+
import { getEndpointDetails } from '../../../constants';
4+
import { ExtendedUsersSchema } from '../../../models';
5+
import { REST_API, USERS_ROUTES } from '../../../api';
6+
7+
export namespace GetUserByIdCommand {
8+
export const url = REST_API.USERS.GET_BY.ID;
9+
export const TSQ_url = url(':id');
10+
11+
export const endpointDetails = getEndpointDetails(
12+
USERS_ROUTES.GET_BY.ID(':id'),
13+
'get',
14+
'Get user by ID',
15+
);
16+
17+
export const RequestSchema = z.object({
18+
id: z.coerce.bigint(),
19+
});
20+
21+
export type Request = z.infer<typeof RequestSchema>;
22+
23+
export const ResponseSchema = z.object({
24+
response: ExtendedUsersSchema,
25+
});
26+
27+
export type Response = z.infer<typeof ResponseSchema>;
28+
}

libs/contract/commands/users/get-by/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './get-user-by-email.command';
2+
export * from './get-user-by-id.command';
23
export * from './get-user-by-short-uuid.command';
34
export * from './get-user-by-tag.command';
45
export * from './get-user-by-telegram-id.command';

libs/contract/constants/cache-keys/cache-keys.constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,15 @@ export const CACHE_KEYS_TTL = {
1717
SUBSCRIPTION_SETTINGS: 3_600_000, // 1 hour
1818
SHORT_UUID_RANGE: 86_400_000, // 1 day
1919
} as const;
20+
21+
export const INTERNAL_CACHE_KEYS = {
22+
NODE_USER_USAGE_PREFIX: 'node_user_usage:',
23+
NODE_USER_USAGE: (nodeId: bigint) =>
24+
`${INTERNAL_CACHE_KEYS.NODE_USER_USAGE_PREFIX}${nodeId.toString()}`,
25+
NODE_USER_USAGE_KEYS: 'node_user_usage_keys',
26+
PROCESSING_POSTFIX: ':processing',
27+
} as const;
28+
29+
export const INTERNAL_CACHE_KEYS_TTL = {
30+
NODE_USER_USAGE: 10_800, // 3 hours in seconds
31+
} as const;

libs/contract/models/users.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { RESET_PERIODS, USERS_STATUS } from '../constants';
44

55
export const UsersSchema = z.object({
66
uuid: z.string().uuid(),
7+
id: z.number(),
78
shortUuid: z.string(),
89
username: z.string(),
910

libs/contract/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@remnawave/backend-contract",
3-
"version": "2.3.26",
3+
"version": "2.3.28",
44
"public": true,
55
"license": "AGPL-3.0-only",
66
"description": "A contract library for Remnawave Backend. It can be used in backend and frontend.",

0 commit comments

Comments
 (0)