@pkcprotocol/pkc-js 0.0.35 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/browser/community/remote-community.d.ts +3 -3
- package/dist/browser/community/remote-community.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/pkc/pkc.js +3 -3
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/runtime/browser/community/local-community.d.ts +2 -0
- package/dist/browser/runtime/browser/community/local-community.js +6 -0
- package/dist/browser/runtime/browser/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/db-handler.js +6 -4
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/challenges.d.ts +26 -0
- package/dist/browser/runtime/node/community/local-community/challenges.js +519 -0
- package/dist/browser/runtime/node/community/local-community/challenges.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.d.ts +9 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.js +165 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.d.ts +11 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +218 -0
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/db-state.d.ts +15 -0
- package/dist/browser/runtime/node/community/local-community/db-state.js +323 -0
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/defaults.d.ts +12 -0
- package/dist/browser/runtime/node/community/local-community/defaults.js +29 -0
- package/dist/browser/runtime/node/community/local-community/defaults.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/editing.d.ts +10 -0
- package/dist/browser/runtime/node/community/local-community/editing.js +188 -0
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.d.ts +12 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +340 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.d.ts +11 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +428 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/publication-store.d.ts +100 -0
- package/dist/browser/runtime/node/community/local-community/publication-store.js +395 -0
- package/dist/browser/runtime/node/community/local-community/publication-store.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.d.ts +9 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.js +493 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/pubsub.d.ts +3 -0
- package/dist/browser/runtime/node/community/local-community/pubsub.js +43 -0
- package/dist/browser/runtime/node/community/local-community/pubsub.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community/registry.d.ts +3 -0
- package/dist/browser/runtime/node/community/local-community/registry.js +4 -0
- package/dist/browser/runtime/node/community/local-community/registry.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community.d.ts +68 -105
- package/dist/browser/runtime/node/community/local-community.js +127 -2927
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/test/test-util.js +0 -1
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/node/community/remote-community.d.ts +3 -3
- package/dist/node/community/remote-community.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/pkc/pkc.js +3 -3
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/runtime/browser/community/local-community.d.ts +2 -0
- package/dist/node/runtime/browser/community/local-community.js +6 -0
- package/dist/node/runtime/browser/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/db-handler.js +6 -4
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/challenges.d.ts +26 -0
- package/dist/node/runtime/node/community/local-community/challenges.js +519 -0
- package/dist/node/runtime/node/community/local-community/challenges.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/cleanup.d.ts +9 -0
- package/dist/node/runtime/node/community/local-community/cleanup.js +165 -0
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.d.ts +11 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.js +218 -0
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/db-state.d.ts +15 -0
- package/dist/node/runtime/node/community/local-community/db-state.js +323 -0
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/defaults.d.ts +12 -0
- package/dist/node/runtime/node/community/local-community/defaults.js +29 -0
- package/dist/node/runtime/node/community/local-community/defaults.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/editing.d.ts +10 -0
- package/dist/node/runtime/node/community/local-community/editing.js +188 -0
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.d.ts +12 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +340 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.d.ts +11 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js +428 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/publication-store.d.ts +100 -0
- package/dist/node/runtime/node/community/local-community/publication-store.js +395 -0
- package/dist/node/runtime/node/community/local-community/publication-store.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.d.ts +9 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.js +493 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/pubsub.d.ts +3 -0
- package/dist/node/runtime/node/community/local-community/pubsub.js +43 -0
- package/dist/node/runtime/node/community/local-community/pubsub.js.map +1 -0
- package/dist/node/runtime/node/community/local-community/registry.d.ts +3 -0
- package/dist/node/runtime/node/community/local-community/registry.js +4 -0
- package/dist/node/runtime/node/community/local-community/registry.js.map +1 -0
- package/dist/node/runtime/node/community/local-community.d.ts +68 -105
- package/dist/node/runtime/node/community/local-community.js +127 -2927
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/test/test-util.js +0 -1
- package/dist/node/test/test-util.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import pLimit from "p-limit";
|
|
2
|
+
import Logger from "../../../../logger.js";
|
|
3
|
+
import { genToArray, removeMfsFilesSafely } from "../../../../util.js";
|
|
4
|
+
import { calculateLocalMfsPathForCommentUpdate } from "./comment-updates.js";
|
|
5
|
+
export async function repinCommentsIPFSIfNeeded(community) {
|
|
6
|
+
const log = Logger("pkc-js:local-community:start:_repinCommentsIPFSIfNeeded");
|
|
7
|
+
const latestCommentCid = community._dbHandler.queryLatestCommentCid(); // latest comment ordered by id
|
|
8
|
+
if (!latestCommentCid)
|
|
9
|
+
return;
|
|
10
|
+
const kuboRpcOrHelia = community._clientsManager.getDefaultKuboRpcClient();
|
|
11
|
+
try {
|
|
12
|
+
await genToArray(kuboRpcOrHelia._client.pin.ls({ paths: latestCommentCid.cid }));
|
|
13
|
+
return; // the comment is already pinned, we assume the rest of the comments are so too
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
if (!e.message.includes("is not pinned"))
|
|
17
|
+
throw e;
|
|
18
|
+
}
|
|
19
|
+
log("The latest comment is not pinned in the ipfs node, pkc-js will repin all existing comment ipfs for community", community.address);
|
|
20
|
+
// latestCommentCid should be the last in unpinnedCommentsFromDb array, in case we throw an error on a comment before it, it does not get pinned
|
|
21
|
+
const unpinnedCommentsFromDb = community._dbHandler.queryAllCommentsOrderedByIdAsc(); // we assume all comments are unpinned if latest comment is not pinned
|
|
22
|
+
// In the _repinCommentIpfs method:
|
|
23
|
+
const limit = pLimit(50);
|
|
24
|
+
const pinningPromises = unpinnedCommentsFromDb.map((unpinnedCommentRow) => limit(async () => {
|
|
25
|
+
if (unpinnedCommentRow.pendingApproval)
|
|
26
|
+
return; // we don't pin comments waiting to get approved
|
|
27
|
+
await community._addCommentRowToIPFS(unpinnedCommentRow, Logger("pkc-js:local-community:start:_repinCommentsIPFSIfNeeded:_addCommentRowToIPFS"));
|
|
28
|
+
}));
|
|
29
|
+
await Promise.all(pinningPromises);
|
|
30
|
+
community._dbHandler.forceUpdateOnAllComments(); // force pkc-js to republish all comment updates
|
|
31
|
+
log(`${unpinnedCommentsFromDb.length} comments' IPFS have been repinned`);
|
|
32
|
+
}
|
|
33
|
+
export async function unpinStaleCids(community) {
|
|
34
|
+
const log = Logger("pkc-js:local-community:sync:unpinStaleCids");
|
|
35
|
+
if (community._cidsToUnPin.size > 0) {
|
|
36
|
+
const sizeBefore = community._cidsToUnPin.size;
|
|
37
|
+
// Create a concurrency limiter with a limit of 50
|
|
38
|
+
const limit = pLimit(50);
|
|
39
|
+
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
40
|
+
// Process all unpinning in parallel with concurrency limit
|
|
41
|
+
await Promise.all(Array.from(community._cidsToUnPin.values()).map((cid) => limit(async () => {
|
|
42
|
+
try {
|
|
43
|
+
await kuboRpc._client.pin.rm(cid, { recursive: true });
|
|
44
|
+
community._cidsToUnPin.delete(cid);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
const error = e;
|
|
48
|
+
if (error.message.startsWith("not pinned")) {
|
|
49
|
+
community._cidsToUnPin.delete(cid);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
log.trace("Failed to unpin cid", cid, "on community", community.address, "due to error", error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})));
|
|
56
|
+
log.trace(`unpinned ${sizeBefore - community._cidsToUnPin.size} stale cids from ipfs node for community (${community.address})`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export async function rmUnneededMfsPaths(community) {
|
|
60
|
+
const log = Logger("pkc-js:local-community:sync:_rmUnneededMfsPaths");
|
|
61
|
+
if (community._mfsPathsToRemove.size > 0) {
|
|
62
|
+
const toDeleteMfsPaths = Array.from(community._mfsPathsToRemove.values());
|
|
63
|
+
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
64
|
+
try {
|
|
65
|
+
await removeMfsFilesSafely({
|
|
66
|
+
kuboRpcClient: kuboRpc,
|
|
67
|
+
paths: toDeleteMfsPaths,
|
|
68
|
+
log
|
|
69
|
+
});
|
|
70
|
+
toDeleteMfsPaths.forEach((path) => community._mfsPathsToRemove.delete(path));
|
|
71
|
+
return toDeleteMfsPaths;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
const error = e;
|
|
75
|
+
if (error.message.includes("file does not exist"))
|
|
76
|
+
return toDeleteMfsPaths; // file does not exist, we can return the paths that were not deleted
|
|
77
|
+
else {
|
|
78
|
+
log.error("Failed to remove paths from MFS", toDeleteMfsPaths, e);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
export async function repinCommentUpdateIfNeeded(community) {
|
|
87
|
+
const log = Logger("pkc-js:start:_repinCommentUpdateIfNeeded");
|
|
88
|
+
// iterating on all comment updates is not efficient, we should figure out a better way
|
|
89
|
+
// Most of the time we run this function, the comment updates are already written to ipfs rpeo
|
|
90
|
+
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
91
|
+
try {
|
|
92
|
+
await kuboRpc._client.files.stat(`/${community.address}`, { hash: true });
|
|
93
|
+
return; // if the directory of this community exists, we assume all the comment updates are there
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
if (!e.message.includes("file does not exist"))
|
|
97
|
+
throw e;
|
|
98
|
+
}
|
|
99
|
+
// community has no comment updates, we can return
|
|
100
|
+
if (!community.lastCommentCid)
|
|
101
|
+
return;
|
|
102
|
+
log(`CommentUpdate directory`, community.address, "will republish all comment updates");
|
|
103
|
+
community._dbHandler.forceUpdateOnAllComments(); // pkc-js will recalculate and publish all comment updates
|
|
104
|
+
}
|
|
105
|
+
export async function cleanUpIpfsRepoRarely(community, force = false) {
|
|
106
|
+
const log = Logger("pkc-js:local-community:syncIpnsWithDb:_cleanUpIpfsRepoRarely");
|
|
107
|
+
if (Math.random() < 0.00001 || force) {
|
|
108
|
+
let gcCids = 0;
|
|
109
|
+
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
110
|
+
try {
|
|
111
|
+
for await (const res of kuboRpc._client.repo.gc({ quiet: true })) {
|
|
112
|
+
if (res.cid)
|
|
113
|
+
gcCids++;
|
|
114
|
+
else
|
|
115
|
+
log.error("Failed to GC ipfs repo due to error", res.err);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
log.error("Failed to GC ipfs repo due to error", e);
|
|
120
|
+
}
|
|
121
|
+
log("GC cleaned", gcCids, "cids out of the IPFS node");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export async function addAllCidsUnderPurgedCommentToBeRemoved(community, purgedCommentAndCommentUpdate) {
|
|
125
|
+
community._cidsToUnPin.add(purgedCommentAndCommentUpdate.commentTableRow.cid);
|
|
126
|
+
community._blocksToRm.push(purgedCommentAndCommentUpdate.commentTableRow.cid);
|
|
127
|
+
if (typeof purgedCommentAndCommentUpdate.commentUpdateTableRow?.postUpdatesBucket === "number") {
|
|
128
|
+
const localCommentUpdatePath = calculateLocalMfsPathForCommentUpdate(community, purgedCommentAndCommentUpdate.commentTableRow, purgedCommentAndCommentUpdate.commentUpdateTableRow?.postUpdatesBucket);
|
|
129
|
+
community._mfsPathsToRemove.add(localCommentUpdatePath);
|
|
130
|
+
}
|
|
131
|
+
if (purgedCommentAndCommentUpdate?.commentUpdateTableRow?.replies) {
|
|
132
|
+
// replies is DbRepliesFormat — flat per-sort with allPageCids
|
|
133
|
+
const dbReplies = purgedCommentAndCommentUpdate.commentUpdateTableRow.replies;
|
|
134
|
+
for (const sortEntry of Object.values(dbReplies)) {
|
|
135
|
+
if (sortEntry?.allPageCids) {
|
|
136
|
+
for (const cid of sortEntry.allPageCids) {
|
|
137
|
+
community._cidsToUnPin.add(cid);
|
|
138
|
+
community._blocksToRm.push(cid);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export async function purgeDisapprovedCommentsOlderThan(community) {
|
|
145
|
+
if (typeof community.settings?.purgeDisapprovedCommentsOlderThan !== "number")
|
|
146
|
+
return;
|
|
147
|
+
const log = Logger("pkc-js:local-community:_purgeDisapprovedCommentsOlderThan");
|
|
148
|
+
const purgedComments = community._dbHandler.purgeDisapprovedCommentsOlderThan(community.settings.purgeDisapprovedCommentsOlderThan);
|
|
149
|
+
if (!purgedComments || purgedComments.length === 0)
|
|
150
|
+
return;
|
|
151
|
+
log("Purged disapproved comments", purgedComments, "because retention time has passed and it's time to purge them from DB and pages");
|
|
152
|
+
// need to clear out any commentUpdate.postUpdatesBucket
|
|
153
|
+
// need to clear out any comment.cid
|
|
154
|
+
// need to clear out any commentUpdate.replies
|
|
155
|
+
for (const purgedComment of purgedComments)
|
|
156
|
+
for (const purgedCommentAndCommentUpdate of purgedComment.purgedTableRows)
|
|
157
|
+
await addAllCidsUnderPurgedCommentToBeRemoved(community, purgedCommentAndCommentUpdate);
|
|
158
|
+
if (community._mfsPathsToRemove.size > 0)
|
|
159
|
+
await rmUnneededMfsPaths(community);
|
|
160
|
+
if (community.updateCid) {
|
|
161
|
+
community._blocksToRm.push(community.updateCid); // we need to remove current updateCid which references purged comments
|
|
162
|
+
community._cidsToUnPin.add(community.updateCid);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=cleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../../../../../src/runtime/browser/community/local-community/cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIvE,OAAO,EAAE,qCAAqC,EAAE,MAAM,sBAAsB,CAAC;AAE7E,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,SAAyB;IACrE,MAAM,GAAG,GAAG,MAAM,CAAC,yDAAyD,CAAC,CAAC;IAC9E,MAAM,gBAAgB,GAAG,SAAS,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC,CAAC,+BAA+B;IACtG,IAAI,CAAC,gBAAgB;QAAE,OAAO;IAC9B,MAAM,cAAc,GAAG,SAAS,CAAC,eAAe,CAAC,uBAAuB,EAAE,CAAC;IAC3E,IAAI,CAAC;QACD,MAAM,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACjF,OAAO,CAAC,+EAA+E;IAC3F,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,IAAI,CAAS,CAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;YAAE,MAAM,CAAC,CAAC;IAC/D,CAAC;IAED,GAAG,CAAC,8GAA8G,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAEvI,gJAAgJ;IAChJ,MAAM,sBAAsB,GAAG,SAAS,CAAC,UAAU,CAAC,8BAA8B,EAAE,CAAC,CAAC,sEAAsE;IA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;QAAE,MAAM,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC9E,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;QACtB,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,uEAAuE;QACxH,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Logger from "../../../../logger.js";
|
|
2
|
+
import type { CommentsTableRow, CommentUpdateType } from "../../../../publications/comment/types.js";
|
|
3
|
+
import type { LocalCommunity } from "../local-community.js";
|
|
4
|
+
import type { CommentUpdateToWriteToDbAndPublishToIpfs } from "./defaults.js";
|
|
5
|
+
export declare function pubsubTopicWithfallback(community: LocalCommunity): string;
|
|
6
|
+
export declare function calculateLocalMfsPathForCommentUpdate(community: LocalCommunity, postDbComment: Pick<CommentsTableRow, "cid">, timestampRange: number): string;
|
|
7
|
+
export declare function calculateNewCommentUpdate(community: LocalCommunity, comment: CommentsTableRow): Promise<CommentUpdateToWriteToDbAndPublishToIpfs>;
|
|
8
|
+
export declare function validateCommentUpdateSignature(community: LocalCommunity, newCommentUpdate: CommentUpdateType, comment: CommentsTableRow, log: Logger): Promise<void>;
|
|
9
|
+
export declare function updateCommentsThatNeedToBeUpdated(community: LocalCommunity): Promise<CommentUpdateToWriteToDbAndPublishToIpfs[]>;
|
|
10
|
+
export declare function syncPostUpdatesWithIpfs(community: LocalCommunity, commentUpdateRowsToPublishToIpfs: CommentUpdateToWriteToDbAndPublishToIpfs[]): Promise<void>;
|
|
11
|
+
export declare function adjustPostUpdatesBucketsIfNeeded(community: LocalCommunity): Promise<void>;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { stringify as deterministicStringify } from "safe-stable-stringify";
|
|
2
|
+
import * as remeda from "remeda";
|
|
3
|
+
import pLimit from "p-limit";
|
|
4
|
+
import Logger from "../../../../logger.js";
|
|
5
|
+
import { timestamp, writeKuboFilesWithTimeout } from "../../../../util.js";
|
|
6
|
+
import env from "../../../../version.js";
|
|
7
|
+
import { calculateInlineRepliesBudget } from "../../util.js";
|
|
8
|
+
import { cleanUpBeforePublishing, signCommentUpdate, verifyCommentUpdate } from "../../../../signer/signatures.js";
|
|
9
|
+
import { PKCError } from "../../../../pkc-error.js";
|
|
10
|
+
import { getAuthorNameFromWire } from "../../../../publications/publication-author.js";
|
|
11
|
+
import { deriveDbReplies } from "../../util.js";
|
|
12
|
+
import { rmUnneededMfsPaths } from "./cleanup.js";
|
|
13
|
+
export function pubsubTopicWithfallback(community) {
|
|
14
|
+
return community.pubsubTopic || community.address;
|
|
15
|
+
}
|
|
16
|
+
export function calculateLocalMfsPathForCommentUpdate(community, postDbComment, timestampRange) {
|
|
17
|
+
// TODO Can optimize the call below by only asking for timestamp field
|
|
18
|
+
return ["/" + community.address, "postUpdates", timestampRange, postDbComment.cid, "update"].join("/");
|
|
19
|
+
}
|
|
20
|
+
export async function calculateNewCommentUpdate(community, comment) {
|
|
21
|
+
const log = Logger("pkc-js:local-community:_calculateNewCommentUpdate");
|
|
22
|
+
// If we're here that means we're gonna calculate the new update and publish it
|
|
23
|
+
log.trace(`Attempting to calculate new CommentUpdate for comment (${comment.cid}) on community`, community.address);
|
|
24
|
+
// This comment will have the local new CommentUpdate, which we will publish to IPFS fiels
|
|
25
|
+
// It includes new author.community as well as updated values in CommentUpdate (except for replies field)
|
|
26
|
+
const storedCommentUpdate = community._dbHandler.queryCommentUpdateTimestampBucketReplies({ cid: comment.cid });
|
|
27
|
+
const authorDomain = getAuthorNameFromWire(comment.author);
|
|
28
|
+
const calculatedCommentUpdate = community._dbHandler.queryCalculatedCommentUpdate({ comment, authorDomain });
|
|
29
|
+
log.trace("Calculated comment update for comment", comment.cid, "on community", community.address, "with reply count", calculatedCommentUpdate.replyCount);
|
|
30
|
+
const currentTimestamp = timestamp();
|
|
31
|
+
const newUpdatedAt = typeof storedCommentUpdate?.updatedAt === "number" && storedCommentUpdate.updatedAt >= currentTimestamp
|
|
32
|
+
? storedCommentUpdate.updatedAt + 1
|
|
33
|
+
: currentTimestamp;
|
|
34
|
+
const commentUpdatePriorToSigning = {
|
|
35
|
+
...cleanUpBeforePublishing({
|
|
36
|
+
...calculatedCommentUpdate,
|
|
37
|
+
updatedAt: newUpdatedAt,
|
|
38
|
+
protocolVersion: env.PROTOCOL_VERSION
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
const preloadedRepliesPages = "best";
|
|
42
|
+
const inlineRepliesBudget = calculateInlineRepliesBudget({
|
|
43
|
+
comment,
|
|
44
|
+
commentUpdateWithoutReplies: commentUpdatePriorToSigning
|
|
45
|
+
});
|
|
46
|
+
const adjustedPreloadedRepliesPageSizeBytes = Math.max(inlineRepliesBudget, 1);
|
|
47
|
+
const generatedRepliesPages = comment.depth === 0
|
|
48
|
+
? await community._pageGenerator.generatePostPages(comment, preloadedRepliesPages, adjustedPreloadedRepliesPageSizeBytes)
|
|
49
|
+
: await community._pageGenerator.generateReplyPages(comment, preloadedRepliesPages, adjustedPreloadedRepliesPageSizeBytes);
|
|
50
|
+
// we have to make sure not clean up submissions of authors by calling cleanUpBeforePublishing
|
|
51
|
+
if (generatedRepliesPages) {
|
|
52
|
+
if ("singlePreloadedPage" in generatedRepliesPages)
|
|
53
|
+
commentUpdatePriorToSigning.replies = { pages: generatedRepliesPages.singlePreloadedPage };
|
|
54
|
+
else if (generatedRepliesPages.pageCids) {
|
|
55
|
+
commentUpdatePriorToSigning.replies = {
|
|
56
|
+
pageCids: generatedRepliesPages.pageCids,
|
|
57
|
+
pages: remeda.pick(generatedRepliesPages.pages, [preloadedRepliesPages])
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Extract allPageCids from the generation result (not available for singlePreloadedPage case)
|
|
62
|
+
const allPageCids = generatedRepliesPages && !("singlePreloadedPage" in generatedRepliesPages) ? generatedRepliesPages.allPageCids : undefined;
|
|
63
|
+
// Unpin old page CIDs that are no longer in the new generation
|
|
64
|
+
{
|
|
65
|
+
const oldDbReplies = storedCommentUpdate?.replies;
|
|
66
|
+
const oldCids = new Set(oldDbReplies ? Object.values(oldDbReplies).flatMap((sort) => sort?.allPageCids ?? []) : []);
|
|
67
|
+
const newCids = new Set(allPageCids ? Object.values(allPageCids).flat() : []);
|
|
68
|
+
for (const cid of oldCids) {
|
|
69
|
+
if (!newCids.has(cid))
|
|
70
|
+
community._cidsToUnPin.add(cid);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const newCommentUpdate = {
|
|
74
|
+
...commentUpdatePriorToSigning,
|
|
75
|
+
signature: await signCommentUpdate({ update: commentUpdatePriorToSigning, signer: community.signer })
|
|
76
|
+
};
|
|
77
|
+
await validateCommentUpdateSignature(community, newCommentUpdate, comment, log);
|
|
78
|
+
const newPostUpdateBucket = comment.depth === 0 ? community._postUpdatesBuckets.find((bucket) => timestamp() - bucket <= comment.timestamp) : undefined;
|
|
79
|
+
const newLocalMfsPath = typeof newPostUpdateBucket === "number"
|
|
80
|
+
? calculateLocalMfsPathForCommentUpdate(community, comment, newPostUpdateBucket)
|
|
81
|
+
: undefined;
|
|
82
|
+
if (storedCommentUpdate?.postUpdatesBucket &&
|
|
83
|
+
newLocalMfsPath &&
|
|
84
|
+
newPostUpdateBucket &&
|
|
85
|
+
storedCommentUpdate.postUpdatesBucket !== newPostUpdateBucket) {
|
|
86
|
+
const oldPostUpdates = calculateLocalMfsPathForCommentUpdate(community, comment, storedCommentUpdate.postUpdatesBucket).replace("/update", "");
|
|
87
|
+
community._mfsPathsToRemove.add(oldPostUpdates);
|
|
88
|
+
}
|
|
89
|
+
const newCommentUpdateDbRecord = {
|
|
90
|
+
...newCommentUpdate,
|
|
91
|
+
// Store CID refs instead of full inline page data — see deriveDbReplies()
|
|
92
|
+
replies: deriveDbReplies({ replies: newCommentUpdate.replies, allPageCids }),
|
|
93
|
+
postUpdatesBucket: newPostUpdateBucket,
|
|
94
|
+
publishedToPostUpdatesMFS: false,
|
|
95
|
+
insertedAt: timestamp()
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
newCommentUpdate,
|
|
99
|
+
newCommentUpdateToWriteToDb: newCommentUpdateDbRecord,
|
|
100
|
+
localMfsPath: newLocalMfsPath,
|
|
101
|
+
pendingApproval: comment.pendingApproval
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export async function validateCommentUpdateSignature(community, newCommentUpdate, comment, log) {
|
|
105
|
+
// This function should be deleted at some point, once the protocol ossifies
|
|
106
|
+
const verificationOpts = {
|
|
107
|
+
update: newCommentUpdate,
|
|
108
|
+
resolveAuthorNames: false,
|
|
109
|
+
clientsManager: community._clientsManager,
|
|
110
|
+
community,
|
|
111
|
+
comment,
|
|
112
|
+
validatePages: community._pkc.validatePages,
|
|
113
|
+
validateUpdateSignature: true
|
|
114
|
+
};
|
|
115
|
+
const validation = await verifyCommentUpdate(verificationOpts);
|
|
116
|
+
if (!validation.valid) {
|
|
117
|
+
log.error(`CommentUpdate (${comment.cid}) signature is invalid due to (${validation.reason}). This is a critical error`);
|
|
118
|
+
throw new PKCError("ERR_COMMENT_UPDATE_SIGNATURE_IS_INVALID", { validation, verificationOpts });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export async function updateCommentsThatNeedToBeUpdated(community) {
|
|
122
|
+
const log = Logger(`pkc-js:local-community:_updateCommentsThatNeedToBeUpdated`);
|
|
123
|
+
// Get all comments that need to be updated
|
|
124
|
+
const commentsToUpdate = community._dbHandler.queryCommentsToBeUpdated();
|
|
125
|
+
if (commentsToUpdate.length === 0)
|
|
126
|
+
return [];
|
|
127
|
+
community._communityUpdateTrigger = true;
|
|
128
|
+
log(`Will update ${commentsToUpdate.length} comments in this update loop for community (${community.address})`);
|
|
129
|
+
// Group by postCid
|
|
130
|
+
const commentsByPostCid = remeda.groupBy.strict(commentsToUpdate, (x) => x.postCid);
|
|
131
|
+
const allCommentUpdateRows = [];
|
|
132
|
+
// Process different post trees in parallel
|
|
133
|
+
const postLimit = pLimit(10); // Process up to 10 post trees concurrently
|
|
134
|
+
const postProcessingPromises = Object.entries(commentsByPostCid).map(([postCid, commentsForPost]) => postLimit(async () => {
|
|
135
|
+
try {
|
|
136
|
+
// Group by depth
|
|
137
|
+
const commentsByDepth = remeda.groupBy.strict(commentsForPost, (x) => x.depth);
|
|
138
|
+
const depthsKeySorted = remeda.keys.strict(commentsByDepth).sort((a, b) => Number(b) - Number(a)); // Sort depths from highest to lowest
|
|
139
|
+
const postUpdateRows = [];
|
|
140
|
+
// Process each depth level in sequence within this post tree
|
|
141
|
+
for (const depthKey of depthsKeySorted) {
|
|
142
|
+
const commentsAtDepth = commentsByDepth[depthKey];
|
|
143
|
+
// Process all comments at this depth in parallel
|
|
144
|
+
const depthLimit = pLimit(50);
|
|
145
|
+
// Calculate updates for all comments at this depth in parallel
|
|
146
|
+
const depthUpdatePromises = commentsAtDepth.map((comment) => depthLimit(async () => await calculateNewCommentUpdate(community, comment)));
|
|
147
|
+
// Wait for all comments at this depth to be calculated
|
|
148
|
+
const depthResults = await Promise.all(depthUpdatePromises);
|
|
149
|
+
// Batch write all updates for this depth to the database
|
|
150
|
+
community._dbHandler.upsertCommentUpdates(depthResults.map((r) => r.newCommentUpdateToWriteToDb));
|
|
151
|
+
// Add to our results
|
|
152
|
+
postUpdateRows.push(...depthResults);
|
|
153
|
+
}
|
|
154
|
+
return postUpdateRows;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
log.error(`Failed to process post tree ${postCid}:`, error);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}));
|
|
161
|
+
// Wait for all post trees to be processed
|
|
162
|
+
const postResults = await Promise.all(postProcessingPromises);
|
|
163
|
+
// Collect all results
|
|
164
|
+
for (const result of postResults) {
|
|
165
|
+
allCommentUpdateRows.push(...result);
|
|
166
|
+
}
|
|
167
|
+
return allCommentUpdateRows;
|
|
168
|
+
}
|
|
169
|
+
export async function syncPostUpdatesWithIpfs(community, commentUpdateRowsToPublishToIpfs) {
|
|
170
|
+
const log = Logger("pkc-js:local-community:sync:_syncPostUpdatesFilesystemWithIpfs");
|
|
171
|
+
const postUpdatesDirectory = `/${community.address}`;
|
|
172
|
+
const commentUpdatesWithLocalPath = commentUpdateRowsToPublishToIpfs.filter((row) => typeof row.localMfsPath === "string");
|
|
173
|
+
if (commentUpdatesWithLocalPath.length === 0)
|
|
174
|
+
throw Error("No comment updates of posts to publish to postUpdates directory. This is a critical bug");
|
|
175
|
+
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
176
|
+
const removedMfsPaths = await rmUnneededMfsPaths(community);
|
|
177
|
+
let postUpdatesDirectoryCid;
|
|
178
|
+
const BATCH_SIZE = 50;
|
|
179
|
+
for (let index = 0; index < commentUpdatesWithLocalPath.length; index += BATCH_SIZE) {
|
|
180
|
+
const batch = commentUpdatesWithLocalPath.slice(index, index + BATCH_SIZE);
|
|
181
|
+
await Promise.all(batch.map(async (row) => {
|
|
182
|
+
const { localMfsPath, newCommentUpdate } = row;
|
|
183
|
+
const content = deterministicStringify(newCommentUpdate);
|
|
184
|
+
await writeKuboFilesWithTimeout({
|
|
185
|
+
ipfsClient: kuboRpc._client,
|
|
186
|
+
log,
|
|
187
|
+
path: localMfsPath,
|
|
188
|
+
content,
|
|
189
|
+
options: {
|
|
190
|
+
create: true,
|
|
191
|
+
truncate: true,
|
|
192
|
+
parents: true,
|
|
193
|
+
// flush: true to avoid Kubo's global Internal.MFSNoFlushLimit (default 256).
|
|
194
|
+
// Costs some throughput (each write self-flushes instead of batching) but
|
|
195
|
+
// is safe under multi-community concurrency, which the global counter is not.
|
|
196
|
+
flush: true
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
removedMfsPaths.push(localMfsPath);
|
|
200
|
+
}));
|
|
201
|
+
postUpdatesDirectoryCid = await kuboRpc._client.files.flush(postUpdatesDirectory);
|
|
202
|
+
}
|
|
203
|
+
const postUpdatesDirectoryCidString = postUpdatesDirectoryCid?.toString();
|
|
204
|
+
log("Community", community.address, "Synced", commentUpdatesWithLocalPath.length, "post CommentUpdates", "with MFS postUpdates directory", postUpdatesDirectoryCidString);
|
|
205
|
+
community._dbHandler.markCommentsAsPublishedToPostUpdates(commentUpdateRowsToPublishToIpfs.map((row) => row.newCommentUpdate.cid));
|
|
206
|
+
}
|
|
207
|
+
export async function adjustPostUpdatesBucketsIfNeeded(community) {
|
|
208
|
+
if (!community.postUpdates)
|
|
209
|
+
return;
|
|
210
|
+
// Look for posts whose buckets should be changed
|
|
211
|
+
const log = Logger("pkc-js:local-community:start:_adjustPostUpdatesBucketsIfNeeded");
|
|
212
|
+
const postsWithOutdatedPostUpdateBucket = community._dbHandler.queryPostsWithOutdatedBuckets(community._postUpdatesBuckets);
|
|
213
|
+
if (postsWithOutdatedPostUpdateBucket.length === 0)
|
|
214
|
+
return;
|
|
215
|
+
community._dbHandler.forceUpdateOnAllCommentsWithCid(postsWithOutdatedPostUpdateBucket.map((post) => post.cid));
|
|
216
|
+
log(`Found ${postsWithOutdatedPostUpdateBucket.length} posts with outdated buckets and forced their updates`);
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=comment-updates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-updates.js","sourceRoot":"","sources":["../../../../../../src/runtime/browser/community/local-community/comment-updates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,GAAG,MAAM,wBAAwB,CAAC;AACzC,OAAO,EA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CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAAC,SAAyB;IAC5E,IAAI,CAAC,SAAS,CAAC,WAAW;QAAE,OAAO;IACnC,iDAAiD;IAEjD,MAAM,GAAG,GAAG,MAAM,CAAC,gEAAgE,CAAC,CAAC;IACrF,MAAM,iCAAiC,GAAG,SAAS,CAAC,UAAU,CAAC,6BAA6B,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAC5H,IAAI,iCAAiC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAE3D,SAAS,CAAC,UAAU,CAAC,+BAA+B,CAAC,iCAAiC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAEhH,GAAG,CAAC,SAAS,iCAAiC,CAAC,MAAM,uDAAuD,CAAC,CAAC;AAClH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Logger from "../../../../logger.js";
|
|
2
|
+
import type { CreateNewLocalCommunityParsedOptions, InternalCommunityRecordAfterFirstUpdateType, InternalCommunityRecordBeforeFirstUpdateType } from "../../../../community/types.js";
|
|
3
|
+
import type { LocalCommunity } from "../local-community.js";
|
|
4
|
+
export declare function initSignerProps(community: LocalCommunity, newSignerProps: InternalCommunityRecordBeforeFirstUpdateType["signer"]): Promise<void>;
|
|
5
|
+
export declare function importCommunitySignerIntoIpfsIfNeeded(community: LocalCommunity): Promise<void>;
|
|
6
|
+
export declare function getDbInternalState(community: LocalCommunity, lock: boolean): Promise<InternalCommunityRecordAfterFirstUpdateType | InternalCommunityRecordBeforeFirstUpdateType>;
|
|
7
|
+
export declare function updateDbInternalState(community: LocalCommunity, props: Partial<InternalCommunityRecordBeforeFirstUpdateType | InternalCommunityRecordAfterFirstUpdateType>): Promise<InternalCommunityRecordBeforeFirstUpdateType | InternalCommunityRecordAfterFirstUpdateType>;
|
|
8
|
+
export declare function updateInstanceStateWithDbState(community: LocalCommunity): Promise<void>;
|
|
9
|
+
export declare function updateInstancePropsWithStartedCommunityOrDb(community: LocalCommunity): Promise<void>;
|
|
10
|
+
export declare function setChallengesToDefaultIfNotDefined(community: LocalCommunity, log: Logger): Promise<void>;
|
|
11
|
+
export declare function createNewLocalCommunityDb(community: LocalCommunity): Promise<void>;
|
|
12
|
+
export declare function initNewLocalCommunityPropsNoMerge(community: LocalCommunity, newProps: CreateNewLocalCommunityParsedOptions): Promise<void>;
|
|
13
|
+
export declare function initInternalCommunityAfterFirstUpdateNoMerge(community: LocalCommunity, newProps: InternalCommunityRecordAfterFirstUpdateType): Promise<void>;
|
|
14
|
+
export declare function initInternalCommunityBeforeFirstUpdateNoMerge(community: LocalCommunity, newProps: InternalCommunityRecordBeforeFirstUpdateType): Promise<void>;
|
|
15
|
+
export declare function initDbHandlerIfNeeded(community: LocalCommunity): Promise<void>;
|