Skip to content

Commit 01a3cd8

Browse files
authored
fix(scale): compolation issues (#386)
1 parent a0662db commit 01a3cd8

7 files changed

Lines changed: 361 additions & 104 deletions

File tree

services/api/src/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const configSchema = sharedConfigSchema.extend({
5757
BASE_EVENT_ID: z.string().min(20).default("63957849393154643868"),
5858
NOSTR_PROOF_CHANNEL_EVENT_ID: z.string().optional(), // if undefined, then nostr functionalities are disabled
5959
NOSTR_DEFAULT_RELAY_URL: z.string().url().default("wss://nos.lol"),
60+
POLIS_BASE_URL: z.string().url().optional(),
6061
POLIS_CONV_TO_IMPORT_ON_RUN: z.undefined().or(
6162
z
6263
.string()

services/api/src/index.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,18 +1792,6 @@ server.after(() => {
17921792
isIndexed: request.body.isIndexed,
17931793
isLoginRequired: request.body.isLoginRequired,
17941794
isOrgImportOnly: config.IS_ORG_IMPORT_ONLY,
1795-
awsAiLabelSummaryEnable:
1796-
config.AWS_AI_LABEL_SUMMARY_ENABLE &&
1797-
(config.NODE_ENV === "production" ||
1798-
config.NODE_ENV === "staging"),
1799-
awsAiLabelSummaryRegion: config.AWS_AI_LABEL_SUMMARY_REGION,
1800-
awsAiLabelSummaryModelId: config.AWS_AI_LABEL_SUMMARY_MODEL_ID,
1801-
awsAiLabelSummaryTemperature:
1802-
config.AWS_AI_LABEL_SUMMARY_TEMPERATURE,
1803-
awsAiLabelSummaryTopP: config.AWS_AI_LABEL_SUMMARY_TOP_P,
1804-
awsAiLabelSummaryMaxTokens:
1805-
config.AWS_AI_LABEL_SUMMARY_MAX_TOKENS,
1806-
awsAiLabelSummaryPrompt: config.AWS_AI_LABEL_SUMMARY_PROMPT,
18071795
});
18081796
},
18091797
});
@@ -1917,19 +1905,6 @@ server.after(() => {
19171905
didWrite: didWrite,
19181906
userId: deviceStatus.userId,
19191907
baseImageServiceUrl: config.IMAGES_SERVICE_BASE_URL,
1920-
axiosPolis: axiosPolis,
1921-
awsAiLabelSummaryEnable:
1922-
config.AWS_AI_LABEL_SUMMARY_ENABLE &&
1923-
(config.NODE_ENV === "production" ||
1924-
config.NODE_ENV === "staging"),
1925-
awsAiLabelSummaryRegion: config.AWS_AI_LABEL_SUMMARY_REGION,
1926-
awsAiLabelSummaryModelId: config.AWS_AI_LABEL_SUMMARY_MODEL_ID,
1927-
awsAiLabelSummaryTemperature:
1928-
config.AWS_AI_LABEL_SUMMARY_TEMPERATURE,
1929-
awsAiLabelSummaryTopP: config.AWS_AI_LABEL_SUMMARY_TOP_P,
1930-
awsAiLabelSummaryMaxTokens:
1931-
config.AWS_AI_LABEL_SUMMARY_MAX_TOKENS,
1932-
awsAiLabelSummaryPrompt: config.AWS_AI_LABEL_SUMMARY_PROMPT,
19331908
voteNotifMilestones: config.VOTE_NOTIF_MILESTONES,
19341909
});
19351910
reply.send();

services/api/src/service/account.ts

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { log } from "@/app.js";
2-
import { userTable } from "@/shared-backend/schema.js";
2+
import { conversationTable, userTable } from "@/shared-backend/schema.js";
33
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
44
import { eq } from "drizzle-orm";
55
import { getAllUserComments, getUserPosts, getUserVotes } from "./user.js";
@@ -9,9 +9,7 @@ import { nowZeroMs } from "@/shared/util.js";
99
import { logout } from "./auth.js";
1010
import { httpErrors } from "@fastify/sensible";
1111
import { MAX_LENGTH_USERNAME } from "@/shared/shared.js";
12-
import type { AxiosInstance } from "axios";
1312
import { castVoteForOpinionSlugIdFromUserId } from "./voting.js";
14-
import * as polisService from "@/service/polis.js";
1513
import { useCommonPost } from "./common.js";
1614

1715
interface CheckUserNameExistProps {
@@ -614,14 +612,6 @@ interface DeleteAccountProps {
614612
didWrite: string;
615613
userId: string;
616614
baseImageServiceUrl: string;
617-
axiosPolis?: AxiosInstance;
618-
awsAiLabelSummaryEnable: boolean;
619-
awsAiLabelSummaryRegion: string;
620-
awsAiLabelSummaryModelId: string;
621-
awsAiLabelSummaryTemperature: string;
622-
awsAiLabelSummaryTopP: string;
623-
awsAiLabelSummaryMaxTokens: string;
624-
awsAiLabelSummaryPrompt: string;
625615
voteNotifMilestones: number[];
626616
}
627617

@@ -632,14 +622,6 @@ export async function deleteUserAccount({
632622
proof,
633623
didWrite,
634624
baseImageServiceUrl,
635-
axiosPolis,
636-
awsAiLabelSummaryEnable,
637-
awsAiLabelSummaryRegion,
638-
awsAiLabelSummaryModelId,
639-
awsAiLabelSummaryTemperature,
640-
awsAiLabelSummaryTopP,
641-
awsAiLabelSummaryMaxTokens,
642-
awsAiLabelSummaryPrompt,
643625
voteNotifMilestones,
644626
}: DeleteAccountProps) {
645627
// TODO: 1. confirmation should be requested upon account deletion request (phone number or ZKP)
@@ -759,30 +741,14 @@ export async function deleteUserAccount({
759741
db,
760742
conversationSlugId: affectedConversation.conversationSlugId,
761743
});
762-
if (axiosPolis !== undefined) {
763-
const votes = await polisService.getPolisVotes({
764-
db,
765-
conversationId: affectedConversation.conversationId,
766-
conversationSlugId: affectedConversation.conversationSlugId,
767-
});
768-
polisService
769-
.getAndUpdatePolisMath({
770-
db: db,
771-
conversationSlugId: affectedConversation.conversationSlugId,
772-
conversationId: affectedConversation.conversationId,
773-
axiosPolis,
774-
votes,
775-
awsAiLabelSummaryEnable,
776-
awsAiLabelSummaryRegion,
777-
awsAiLabelSummaryModelId,
778-
awsAiLabelSummaryTemperature,
779-
awsAiLabelSummaryTopP,
780-
awsAiLabelSummaryMaxTokens,
781-
awsAiLabelSummaryPrompt,
782-
})
783-
.catch((e: unknown) => {
784-
log.error(e);
785-
});
786-
}
744+
await db
745+
.update(conversationTable)
746+
.set({
747+
needsMathUpdate: true,
748+
mathUpdateRequestedAt: nowZeroMs(),
749+
})
750+
.where(
751+
eq(conversationTable.id, affectedConversation.conversationId),
752+
);
787753
}
788754
}

services/api/src/service/import.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
MAX_LENGTH_TITLE,
1212
toUnionUndefined,
1313
} from "@/shared/shared.js";
14+
import { conversationTable } from "@/shared-backend/schema.js";
15+
import { nowZeroMs } from "@/shared/util.js";
16+
import { eq } from "drizzle-orm";
1417

1518
interface LoadImportedPolisConversationProps {
1619
db: PostgresDatabase;
@@ -39,6 +42,7 @@ export async function loadImportedPolisConversation({
3942
isLoginRequired,
4043
isIndexed,
4144
}: LoadImportedPolisConversationProps): Promise<ConversationIds> {
45+
const now = nowZeroMs();
4246
// create conversation
4347
const ownername = importedPolisConversation.conversation_data.ownername;
4448
const importCreatedAt =
@@ -175,6 +179,13 @@ export async function loadImportedPolisConversation({
175179
opinionCount: opinionCount,
176180
voteCount: voteCount,
177181
});
182+
await db
183+
.update(conversationTable)
184+
.set({
185+
needsMathUpdate: true,
186+
mathUpdateRequestedAt: now,
187+
})
188+
.where(eq(conversationTable.id, conversationId));
178189
return { conversationSlugId, conversationId, conversationContentId };
179190
} catch (e) {
180191
// TODO: make incremental transactions, implement batch mechanisms to allow for resuming importing that failed midway

services/api/src/service/post.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ interface ImportPostProps {
5757
isIndexed: boolean;
5858
isLoginRequired: boolean;
5959
isOrgImportOnly: boolean;
60-
awsAiLabelSummaryEnable: boolean;
61-
awsAiLabelSummaryRegion: string;
62-
awsAiLabelSummaryModelId: string;
63-
awsAiLabelSummaryTemperature: string;
64-
awsAiLabelSummaryTopP: string;
65-
awsAiLabelSummaryMaxTokens: string;
66-
awsAiLabelSummaryPrompt: string;
6760
}
6861

6962
export async function importConversation({
@@ -78,13 +71,6 @@ export async function importConversation({
7871
isLoginRequired,
7972
isIndexed,
8073
isOrgImportOnly,
81-
awsAiLabelSummaryEnable,
82-
awsAiLabelSummaryRegion,
83-
awsAiLabelSummaryModelId,
84-
awsAiLabelSummaryTemperature,
85-
awsAiLabelSummaryTopP,
86-
awsAiLabelSummaryMaxTokens,
87-
awsAiLabelSummaryPrompt,
8874
}: ImportPostProps): Promise<ImportConversationResponse> {
8975
if (
9076
(postAsOrganization === undefined || postAsOrganization === "") &&
@@ -112,7 +98,7 @@ export async function importConversation({
11298
polisUrl: polisUrl,
11399
axiosPolis: axiosPolis,
114100
});
115-
const { conversationId, conversationSlugId } =
101+
const { conversationSlugId } =
116102
await importService.loadImportedPolisConversation({
117103
db,
118104
importedPolisConversation,
@@ -126,26 +112,6 @@ export async function importConversation({
126112
isLoginRequired,
127113
isIndexed,
128114
});
129-
const votes = await polisService.getPolisVotes({
130-
db,
131-
conversationId,
132-
conversationSlugId,
133-
});
134-
await polisService.getAndUpdatePolisMath({
135-
db: db,
136-
conversationSlugId: conversationSlugId,
137-
conversationId: conversationId,
138-
axiosPolis,
139-
votes: votes,
140-
awsAiLabelSummaryEnable,
141-
awsAiLabelSummaryRegion,
142-
awsAiLabelSummaryModelId,
143-
awsAiLabelSummaryTemperature,
144-
awsAiLabelSummaryTopP,
145-
awsAiLabelSummaryMaxTokens,
146-
awsAiLabelSummaryPrompt,
147-
});
148-
149115
return {
150116
conversationSlugId: conversationSlugId,
151117
};

services/math-updater/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@
3737
"pino": "^9.6.0",
3838
"pino-pretty": "^13.1.1",
3939
"postgres": "^3.4.5",
40+
"sanitize-html": "^2.17.0",
4041
"uint8arrays": "^5.1.0",
4142
"zod": "^3.24.4"
4243
},
4344
"devDependencies": {
4445
"@eslint/js": "^9.27.0",
4546
"@types/eslint__js": "^8.42.3",
4647
"@types/node": "^20.17.47",
48+
"@types/sanitize-html": "^2.16.0",
4749
"eslint": "^9.27.0",
4850
"eslint-config-prettier": "^9.1.0",
4951
"esm-module-alias": "^2.2.1",
52+
"fastify": "^5.6.1",
5053
"globals": "^15.15.0",
5154
"prettier": "^3.5.3",
5255
"tsx": "^4.19.4",

0 commit comments

Comments
 (0)