@pkcprotocol/pkc-js 0.0.156 → 0.0.158
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 +55 -3
- package/dist/browser/clients/base-client-manager.js +10 -1
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/clients/rpc-client/schema.d.ts +1 -0
- package/dist/browser/clients/shared-pubsub-topic-list.d.ts +14 -0
- package/dist/browser/clients/shared-pubsub-topic-list.js +61 -0
- package/dist/browser/clients/shared-pubsub-topic-list.js.map +1 -0
- package/dist/browser/community/schema.d.ts +13 -0
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/index-with-compile-cache.d.ts +2 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/pages/schema.d.ts +3 -0
- package/dist/browser/publications/comment/comment.d.ts +1 -0
- package/dist/browser/publications/comment/comment.js +1 -0
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/comment/schema.d.ts +4 -2
- package/dist/browser/publications/comment/schema.js +2 -0
- package/dist/browser/publications/comment/schema.js.map +1 -1
- package/dist/browser/publications/comment-moderation/schema.js +2 -2
- package/dist/browser/publications/comment-moderation/schema.js.map +1 -1
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +2 -0
- package/dist/browser/rpc/src/schema.d.ts +12 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +3 -0
- package/dist/browser/runtime/node/community/db-handler.js +51 -14
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/cleanup.js +6 -0
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.d.ts +6 -0
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +85 -12
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +102 -61
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.d.ts +21 -0
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js +141 -4
- package/dist/browser/runtime/node/community/local-community/post-updates-bucket.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/pubsub.js +11 -4
- package/dist/browser/runtime/node/community/local-community/pubsub.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.d.ts +22 -4
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js +45 -9
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +4 -0
- package/dist/browser/runtime/node/community/local-community.js +16 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/event-loop-watch.d.ts +13 -0
- package/dist/browser/runtime/node/event-loop-watch.js +58 -0
- package/dist/browser/runtime/node/event-loop-watch.js.map +1 -0
- package/dist/browser/schema/schema-util.d.ts +5 -0
- package/dist/browser/schema/schema.d.ts +9 -0
- package/dist/browser/schema/schema.js +9 -1
- package/dist/browser/schema/schema.js.map +1 -1
- package/dist/browser/schema.d.ts +16 -0
- package/dist/browser/test/test-util.d.ts +5 -0
- package/dist/browser/version.js +1 -1
- package/dist/bundled/bundle-manifest.json +43 -40
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-CceaAEzV.js → helia-for-pkc-D3uvabO4.js} +2 -2
- package/dist/bundled/chunks/{local-community-C8Qwak8F.js → local-community-ChB5dbEH.js} +1 -1
- package/dist/bundled/chunks/{local-community-BzZbcwm-.js → local-community-SgssDrxj.js} +416 -90
- package/dist/bundled/chunks/{node-CleFjKjX.js → node-Bx3xTqFv.js} +6 -5
- package/dist/bundled/chunks/{page-sort-scoring-BAl6dNeR.js → page-sort-scoring-CZmdHvps.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-CW6GnMsd.js → rpc-local-community-D66Be62U.js} +51 -4
- package/dist/bundled/chunks/{util-C0MpIK71.js → util-BuTE1Bd1.js} +7 -8
- package/dist/bundled/chunks/{util-C29b1mlK.js → util-CodXreIl.js} +1 -1
- package/dist/bundled/chunks/{validate-package-factories-CAwF_8n6.js → validate-package-factories-Bc4uoozL.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/clients/base-client-manager.js +10 -1
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/clients/rpc-client/schema.d.ts +1 -0
- package/dist/node/clients/shared-pubsub-topic-list.d.ts +14 -0
- package/dist/node/clients/shared-pubsub-topic-list.js +61 -0
- package/dist/node/clients/shared-pubsub-topic-list.js.map +1 -0
- package/dist/node/community/schema.d.ts +13 -0
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/index-with-compile-cache.d.ts +2 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/pages/schema.d.ts +3 -0
- package/dist/node/publications/comment/comment.d.ts +1 -0
- package/dist/node/publications/comment/comment.js +1 -0
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/comment/schema.d.ts +4 -2
- package/dist/node/publications/comment/schema.js +2 -0
- package/dist/node/publications/comment/schema.js.map +1 -1
- package/dist/node/publications/comment-moderation/schema.js +2 -2
- package/dist/node/publications/comment-moderation/schema.js.map +1 -1
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +2 -0
- package/dist/node/rpc/src/schema.d.ts +12 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +3 -0
- package/dist/node/runtime/node/community/db-handler.js +51 -14
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/cleanup.js +6 -0
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.d.ts +6 -0
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +85 -12
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +102 -61
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.d.ts +21 -0
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js +141 -4
- package/dist/node/runtime/node/community/local-community/post-updates-bucket.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/pubsub.js +11 -4
- package/dist/node/runtime/node/community/local-community/pubsub.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.d.ts +22 -4
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js +45 -9
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +4 -0
- package/dist/node/runtime/node/community/local-community.js +16 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/event-loop-watch.d.ts +13 -0
- package/dist/node/runtime/node/event-loop-watch.js +58 -0
- package/dist/node/runtime/node/event-loop-watch.js.map +1 -0
- package/dist/node/schema/schema-util.d.ts +5 -0
- package/dist/node/schema/schema.d.ts +9 -0
- package/dist/node/schema/schema.js +9 -1
- package/dist/node/schema/schema.js.map +1 -1
- package/dist/node/schema.d.ts +16 -0
- package/dist/node/test/test-util.d.ts +5 -0
- package/dist/node/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { i as __toESM } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $n as CommentEditsTableRowSchema, Ar as t$4, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Br as messages, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingCommunity, Dr as t$3, Dt as require_sha256, En as VotePubsubReservedFields, Er as r$1, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, Nr as require_retry, On as VoteTablesRowSchema, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Sr as t$6, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Vn as CommentUpdateTableRowSchema, Vr as logger_default, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Zn as CommentEditReservedFields, _ as genToArray, b as getIpnsRecordInLocalKuboNode, br as n$2, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, ri as ZodError, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$3, wr as e, wt as untrackStartedCommunity, xr as t$5, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$7, zn as CommentUpdateSchema, zr as PKCError, zt as DecryptedChallengeRequestPublicationSchema } from "./util-
|
|
3
|
-
import { $ as
|
|
4
|
-
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-
|
|
2
|
+
import { $n as CommentEditsTableRowSchema, Ar as t$4, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Br as messages, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingCommunity, Dr as t$3, Dt as require_sha256, En as VotePubsubReservedFields, Er as r$1, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, Nr as require_retry, On as VoteTablesRowSchema, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Sr as t$6, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Vn as CommentUpdateTableRowSchema, Vr as logger_default, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Zn as CommentEditReservedFields, _ as genToArray, b as getIpnsRecordInLocalKuboNode, br as n$2, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, ri as ZodError, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$3, wr as e, wt as untrackStartedCommunity, xr as t$5, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$7, zn as CommentUpdateSchema, zr as PKCError, zt as DecryptedChallengeRequestPublicationSchema } from "./util-BuTE1Bd1.js";
|
|
3
|
+
import { $ as coerceSchemaRowJson, $n as getAuthorNameFromWire, $r as n$5, Ar as getDefaultCommunityDbConfig, Bn as verifyCommentPubsubMessage, Br as resolveDbPostsCidRefs, Cn as signChallengeVerification, Dn as signCommentUpdate, Dr as deriveDbReplies, Er as deriveDbPosts, Et as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Fn as verifyChallengeRequest, Gn as verifyVote, Gr as markCommunityDbAsBeingWritten, H as listSubscribedPubsubTopicsShared, Hn as verifyCommunity, K as pLimit, Kr as findCommunitiesEntry, Ln as verifyCommentEdit, Lr as moveCommunityDbToDeletedDirectory, Mr as getThumbnailPropsOfLink, N as MAX_PAGE_SIZE_BYTES, Nn as verifyChallengeAnswer, Nr as importSignerIntoKuboNode, On as signCommentUpdateForChallengeVerification, Q as coerceSchemaRowBoolean, Qr as t$8, Rn as verifyCommentIpfs, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sr as calculateInlineRepliesBudget, Tn as signCommentEdit, Tr as deriveCommentIpfsFromCommentTableRow, Un as verifyCommunityEdit, Ur as unregisterLocalCommunity, V as SHARED_KUBO_READ_TIMEOUT_MS, Vn as verifyCommentUpdate, Wr as getCommunitiesRegistry, Xn as buildRuntimeAuthor, Xr as t$11, Yr as t$10, Zn as cleanWireAuthor, Zr as r$2, _ as createAuthorIdentityMatcher, _n as encryptEd25519AesGcmPublicKeyBuffer, _r as getPKCAddressFromPublicKeySync, a as generatePagesReportingFailedSorts, ar as crosspostChainDepthUpTo, b as KeyvBetterSqlite3, br as backupCommunityDb, c as resolvePageSortsOrThrow, ci as require_lodash_merge, d as getChallengeVerification, dn as SignerWithPublicKeyAddress, ei as n$4, et as collectSchemaRowCoercions, f as getCommunityChallengeFromCommunityChallengeSettings, fr as decode, g as authorNameResolveFailureReason, gr as getPKCAddressFromPublicKey, h as authorIdentityMatcherForRequest, hn as decryptEd25519AesGcmPublicKeyBuffer, hr as getIpfsKeyFromPrivateKey, ht as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, i as derivePublicPageSorts, j as iterateOverPageCidsToFindAllCids, kn as signCommunity, kr as forgetCommunityThatFailedToBeDeleted, kt as parseJsonWithPKCErrorIfFails, ln as verifyAuthorWalletEntry, lr as getCommunityNameFromWire, m as pkcJsChallenges, ni as t$9, o as loadPageSortsForStartedCommunity, or as effectiveMaxCrosspostDepth, p as loadChallengeFileFromCommunityChallengeSettings, pr as encode, pt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, qn as forbiddenKeysOf, r as computePageSortsFingerprint, s as lookupPageSortFactories, si as STORAGE_KEYS, t as RpcLocalCommunity, tr as stringify, tt as createSchemaRowParser, u as deriveCommunityChallengesOrThrow, ur as getCommunityPublicKeyFromWire, v as TrackedInstanceRegistry, vn as _validateSignatureOfPKCRecord, vr as getPublicKeyFromPrivateKey, w as TIMEFRAMES_TO_SECONDS, wn as signComment, wr as deleteOldCommunityInWindows, xn as signChallengeMessage, xr as calculateExpectedSignatureSize, y as LRUCache, yn as cleanUpBeforePublishing, yr as BackupAbortError, zn as verifyCommentModeration, zr as removeFileRetryingWhileBusy } from "./rpc-local-community-D66Be62U.js";
|
|
4
|
+
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-CZmdHvps.js";
|
|
5
5
|
import { c as prepare, n as decode$1, r as encode$1 } from "./src-BSYNGtIQ.js";
|
|
6
6
|
import { t as UnixFS } from "./src-CAvdjq_i.js";
|
|
7
|
+
import { monitorEventLoopDelay } from "node:perf_hooks";
|
|
7
8
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
9
|
import path from "node:path";
|
|
9
10
|
import os from "os";
|
|
@@ -1449,6 +1450,9 @@ const TABLES = Object.freeze({
|
|
|
1449
1450
|
COMMENT_EDITS: "commentEdits",
|
|
1450
1451
|
PSEUDONYMITY_ALIASES: "pseudonymityAliases"
|
|
1451
1452
|
});
|
|
1453
|
+
function isAuthorBanRow(modEdit) {
|
|
1454
|
+
return typeof modEdit?.banExpiresAt === "number" && modEdit.banExpiresAt > 0;
|
|
1455
|
+
}
|
|
1452
1456
|
function deriveAliasOriginalAuthorSignerAddress(originalAuthorPublicKey) {
|
|
1453
1457
|
try {
|
|
1454
1458
|
return getPKCAddressFromPublicKeySync(originalAuthorPublicKey);
|
|
@@ -1457,9 +1461,14 @@ function deriveAliasOriginalAuthorSignerAddress(originalAuthorPublicKey) {
|
|
|
1457
1461
|
}
|
|
1458
1462
|
}
|
|
1459
1463
|
var DbHandler = class {
|
|
1464
|
+
_notePublicationWrite() {
|
|
1465
|
+
this._publicationWriteGeneration++;
|
|
1466
|
+
if (this._community && this._readBackWithoutStoringDepth === 0) this._community._communityUpdateTrigger = true;
|
|
1467
|
+
}
|
|
1460
1468
|
constructor(community) {
|
|
1461
1469
|
this._transactionGeneration = 0;
|
|
1462
1470
|
this._publicationWriteGeneration = 0;
|
|
1471
|
+
this._readBackWithoutStoringDepth = 0;
|
|
1463
1472
|
this._startLockAddress = void 0;
|
|
1464
1473
|
this._community = community;
|
|
1465
1474
|
this._transactionDepth = 0;
|
|
@@ -1597,10 +1606,13 @@ var DbHandler = class {
|
|
|
1597
1606
|
}
|
|
1598
1607
|
readBackWithoutStoring(opts) {
|
|
1599
1608
|
this._db.exec("SAVEPOINT read_back_without_storing");
|
|
1609
|
+
this._readBackWithoutStoringDepth++;
|
|
1600
1610
|
try {
|
|
1601
1611
|
opts.write();
|
|
1602
1612
|
return opts.read();
|
|
1603
1613
|
} finally {
|
|
1614
|
+
this._readBackWithoutStoringDepth--;
|
|
1615
|
+
this._publicationWriteGeneration++;
|
|
1604
1616
|
this._db.exec("ROLLBACK TO read_back_without_storing");
|
|
1605
1617
|
this._db.exec("RELEASE read_back_without_storing");
|
|
1606
1618
|
}
|
|
@@ -1698,6 +1710,7 @@ var DbHandler = class {
|
|
|
1698
1710
|
removed INTEGER NULLABLE, -- BOOLEAN (0/1)
|
|
1699
1711
|
approved INTEGER NULLABLE, -- BOOLEAN (0/1)
|
|
1700
1712
|
reason TEXT NULLABLE,
|
|
1713
|
+
authorBanExpiresAt INTEGER NULLABLE, -- the ban a mod published on this comment (issue #363)
|
|
1701
1714
|
updatedAt INTEGER NOT NULL CHECK(updatedAt > 0),
|
|
1702
1715
|
protocolVersion TEXT NOT NULL,
|
|
1703
1716
|
signature TEXT NOT NULL, -- JSON
|
|
@@ -2237,15 +2250,15 @@ var DbHandler = class {
|
|
|
2237
2250
|
}
|
|
2238
2251
|
}
|
|
2239
2252
|
deleteVote(authorSignerAddress, commentCid) {
|
|
2240
|
-
this.
|
|
2253
|
+
this._notePublicationWrite();
|
|
2241
2254
|
this._db.prepare(`DELETE FROM ${TABLES.VOTES} WHERE commentCid = ? AND authorSignerAddress = ?`).run(commentCid, authorSignerAddress);
|
|
2242
2255
|
}
|
|
2243
2256
|
_deleteCommentEditRow(rowid) {
|
|
2244
|
-
this.
|
|
2257
|
+
this._notePublicationWrite();
|
|
2245
2258
|
return this._db.prepare(`DELETE FROM ${TABLES.COMMENT_EDITS} WHERE rowid = ?`).run(rowid).changes > 0;
|
|
2246
2259
|
}
|
|
2247
2260
|
insertVotes(votes) {
|
|
2248
|
-
this.
|
|
2261
|
+
this._notePublicationWrite();
|
|
2249
2262
|
if (votes.length === 0) return;
|
|
2250
2263
|
const processedVotes = this._processRecordsForDbBeforeInsert(votes);
|
|
2251
2264
|
const columnNames = this._getColumnNames(TABLES.VOTES);
|
|
@@ -2269,7 +2282,7 @@ var DbHandler = class {
|
|
|
2269
2282
|
})(processedVotes);
|
|
2270
2283
|
}
|
|
2271
2284
|
insertComments(comments) {
|
|
2272
|
-
this.
|
|
2285
|
+
this._notePublicationWrite();
|
|
2273
2286
|
if (comments.length === 0) return;
|
|
2274
2287
|
const processedComments = this._processRecordsForDbBeforeInsert(comments);
|
|
2275
2288
|
const columnNames = this._getColumnNames(TABLES.COMMENTS);
|
|
@@ -2290,7 +2303,7 @@ var DbHandler = class {
|
|
|
2290
2303
|
})(processedComments);
|
|
2291
2304
|
}
|
|
2292
2305
|
insertPseudonymityAliases(aliases) {
|
|
2293
|
-
this.
|
|
2306
|
+
this._notePublicationWrite();
|
|
2294
2307
|
if (aliases.length === 0) return;
|
|
2295
2308
|
const processedAliases = this._processRecordsForDbBeforeInsert(aliases).map((alias) => ({
|
|
2296
2309
|
...alias,
|
|
@@ -2310,14 +2323,14 @@ var DbHandler = class {
|
|
|
2310
2323
|
const columnNames = this._getColumnNames(TABLES.COMMENT_UPDATES);
|
|
2311
2324
|
const stmt = this._prepareCached(`
|
|
2312
2325
|
INSERT INTO ${TABLES.COMMENT_UPDATES}
|
|
2313
|
-
(cid, edit, upvoteCount, downvoteCount, replyCount, childCount, number, postNumber, flairs, spoiler, nsfw, pinned, locked, archived, removed, approved, reason, updatedAt, protocolVersion, signature, author, replies, lastChildCid, lastReplyTimestamp, postUpdatesBucket, publishedToPostUpdatesMFS, insertedAt, extraProps)
|
|
2314
|
-
VALUES (@cid, @edit, @upvoteCount, @downvoteCount, @replyCount, @childCount, @number, @postNumber, @flairs, @spoiler, @nsfw, @pinned, @locked, @archived, @removed, @approved, @reason, @updatedAt, @protocolVersion, @signature, @author, @replies, @lastChildCid, @lastReplyTimestamp, @postUpdatesBucket, @publishedToPostUpdatesMFS, @insertedAt, @extraProps)
|
|
2326
|
+
(cid, edit, upvoteCount, downvoteCount, replyCount, childCount, number, postNumber, flairs, spoiler, nsfw, pinned, locked, archived, removed, approved, reason, authorBanExpiresAt, updatedAt, protocolVersion, signature, author, replies, lastChildCid, lastReplyTimestamp, postUpdatesBucket, publishedToPostUpdatesMFS, insertedAt, extraProps)
|
|
2327
|
+
VALUES (@cid, @edit, @upvoteCount, @downvoteCount, @replyCount, @childCount, @number, @postNumber, @flairs, @spoiler, @nsfw, @pinned, @locked, @archived, @removed, @approved, @reason, @authorBanExpiresAt, @updatedAt, @protocolVersion, @signature, @author, @replies, @lastChildCid, @lastReplyTimestamp, @postUpdatesBucket, @publishedToPostUpdatesMFS, @insertedAt, @extraProps)
|
|
2315
2328
|
ON CONFLICT(cid) DO UPDATE SET
|
|
2316
2329
|
edit = excluded.edit, upvoteCount = excluded.upvoteCount, downvoteCount = excluded.downvoteCount, replyCount = excluded.replyCount, childCount = excluded.childCount,
|
|
2317
2330
|
number = COALESCE(excluded.number, ${TABLES.COMMENT_UPDATES}.number),
|
|
2318
2331
|
postNumber = COALESCE(excluded.postNumber, ${TABLES.COMMENT_UPDATES}.postNumber),
|
|
2319
2332
|
flairs = excluded.flairs, spoiler = excluded.spoiler, nsfw = excluded.nsfw, pinned = excluded.pinned, locked = excluded.locked, archived = excluded.archived,
|
|
2320
|
-
removed = excluded.removed, approved = excluded.approved, reason = excluded.reason, updatedAt = excluded.updatedAt, protocolVersion = excluded.protocolVersion,
|
|
2333
|
+
removed = excluded.removed, approved = excluded.approved, reason = excluded.reason, authorBanExpiresAt = excluded.authorBanExpiresAt, updatedAt = excluded.updatedAt, protocolVersion = excluded.protocolVersion,
|
|
2321
2334
|
signature = excluded.signature, author = excluded.author, replies = excluded.replies, lastChildCid = excluded.lastChildCid,
|
|
2322
2335
|
lastReplyTimestamp = excluded.lastReplyTimestamp, postUpdatesBucket = excluded.postUpdatesBucket,
|
|
2323
2336
|
publishedToPostUpdatesMFS = excluded.publishedToPostUpdatesMFS,
|
|
@@ -2336,7 +2349,7 @@ var DbHandler = class {
|
|
|
2336
2349
|
})(processedUpdates);
|
|
2337
2350
|
}
|
|
2338
2351
|
insertCommentModerations(moderations) {
|
|
2339
|
-
this.
|
|
2352
|
+
this._notePublicationWrite();
|
|
2340
2353
|
if (moderations.length === 0) return;
|
|
2341
2354
|
const processedModerations = this._processRecordsForDbBeforeInsert(moderations);
|
|
2342
2355
|
const columnNames = this._getColumnNames(TABLES.COMMENT_MODERATIONS);
|
|
@@ -2357,7 +2370,7 @@ var DbHandler = class {
|
|
|
2357
2370
|
})(processedModerations);
|
|
2358
2371
|
}
|
|
2359
2372
|
insertCommentEdits(edits) {
|
|
2360
|
-
this.
|
|
2373
|
+
this._notePublicationWrite();
|
|
2361
2374
|
if (edits.length === 0) return;
|
|
2362
2375
|
const processedEdits = this._processRecordsForDbBeforeInsert(edits);
|
|
2363
2376
|
const columnNames = this._getColumnNames(TABLES.COMMENT_EDITS);
|
|
@@ -3157,7 +3170,7 @@ var DbHandler = class {
|
|
|
3157
3170
|
]);
|
|
3158
3171
|
}
|
|
3159
3172
|
removeCommentFromPendingApproval(comment) {
|
|
3160
|
-
this.
|
|
3173
|
+
this._notePublicationWrite();
|
|
3161
3174
|
const log = logger_default("pkc-js:local-community:db-handler:removeCommentFromPendingApproval");
|
|
3162
3175
|
const res = this._db.prepare(`UPDATE ${TABLES.COMMENTS} SET pendingApproval = 0 WHERE cid = ?`).run(comment.cid);
|
|
3163
3176
|
log.trace(`Removed pendingApproval for cid=${comment.cid}, changes=${res.changes}`);
|
|
@@ -3353,6 +3366,7 @@ var DbHandler = class {
|
|
|
3353
3366
|
flairs: moderation?.flairs || authorEdit?.flairs || comment.challengeCommentUpdate?.flairs,
|
|
3354
3367
|
...moderation?.flags,
|
|
3355
3368
|
reason: moderation?.reason ?? comment.challengeCommentUpdate?.reason,
|
|
3369
|
+
authorBanExpiresAt: moderation?.authorBanExpiresAt || void 0,
|
|
3356
3370
|
author: { community: {
|
|
3357
3371
|
...challengeAuthorCommunity ?? {},
|
|
3358
3372
|
...authorCommunity
|
|
@@ -3488,6 +3502,8 @@ var DbHandler = class {
|
|
|
3488
3502
|
result.set(row.commentCid, summary);
|
|
3489
3503
|
}
|
|
3490
3504
|
if (summary.reason === void 0 && typeof moderation.reason === "string") summary.reason = moderation.reason;
|
|
3505
|
+
const banExpiresAt = moderation.author?.banExpiresAt;
|
|
3506
|
+
if (summary.authorBanExpiresAt === void 0 && typeof banExpiresAt === "number") summary.authorBanExpiresAt = banExpiresAt;
|
|
3491
3507
|
if (summary.flairs === void 0 && moderation.flairs !== null && moderation.flairs !== void 0) summary.flairs = moderation.flairs;
|
|
3492
3508
|
if (summary.approved === void 0 && moderation.approved !== null && moderation.approved !== void 0) summary.approved = Boolean(moderation.approved);
|
|
3493
3509
|
for (const flag of FLAG_NAMES) if (summary.flags[flag] === void 0 && moderation[flag] !== null && moderation[flag] !== void 0) summary.flags[flag] = Boolean(moderation[flag]);
|
|
@@ -3606,7 +3622,7 @@ var DbHandler = class {
|
|
|
3606
3622
|
for (const need of uncached.values()) {
|
|
3607
3623
|
const modEditSet = new Set(need.modEdit);
|
|
3608
3624
|
const modAuthorEdits = modEditRows.filter((row) => row.targetAuthorSignerAddress !== null && modEditSet.has(row.targetAuthorSignerAddress) || need.domain !== void 0 && row.targetAuthorDomain === need.domain).map((row) => row.author);
|
|
3609
|
-
const banAuthor = modAuthorEdits.find(
|
|
3625
|
+
const banAuthor = modAuthorEdits.find(isAuthorBanRow);
|
|
3610
3626
|
const authorFlairsByMod = modAuthorEdits.find((modEdit) => modEdit?.flairs);
|
|
3611
3627
|
const modEdits = {};
|
|
3612
3628
|
if (banAuthor?.banExpiresAt) modEdits.banExpiresAt = banAuthor.banExpiresAt;
|
|
@@ -3758,7 +3774,7 @@ var DbHandler = class {
|
|
|
3758
3774
|
SELECT json_extract(commentModeration, '$.author') AS commentAuthorJson FROM ${TABLES.COMMENT_MODERATIONS}
|
|
3759
3775
|
WHERE (${conditions.join(" OR ")}) AND json_extract(commentModeration, '$.author') IS NOT NULL ORDER BY rowid DESC
|
|
3760
3776
|
`).all(...params).map((r) => JSON.parse(r.commentAuthorJson));
|
|
3761
|
-
const banAuthor = modAuthorEdits.find(
|
|
3777
|
+
const banAuthor = modAuthorEdits.find(isAuthorBanRow);
|
|
3762
3778
|
const authorFlairsByMod = modAuthorEdits.find((modEdit) => modEdit?.flairs);
|
|
3763
3779
|
const aggregateAuthor = {};
|
|
3764
3780
|
if (banAuthor?.banExpiresAt) aggregateAuthor.banExpiresAt = banAuthor.banExpiresAt;
|
|
@@ -3873,7 +3889,7 @@ var DbHandler = class {
|
|
|
3873
3889
|
return allCids;
|
|
3874
3890
|
}
|
|
3875
3891
|
purgeComment(cid, isNestedCall = false) {
|
|
3876
|
-
this.
|
|
3892
|
+
this._notePublicationWrite();
|
|
3877
3893
|
const log = logger_default("pkc-js:local-community:db-handler:purgeComment");
|
|
3878
3894
|
const purgedRecords = [];
|
|
3879
3895
|
if (!isNestedCall) this.createTransaction();
|
|
@@ -4029,6 +4045,9 @@ var DbHandler = class {
|
|
|
4029
4045
|
if (commentCids.length === 0) return;
|
|
4030
4046
|
this._runForEachCidBatch(commentCids, (placeholders) => `UPDATE ${TABLES.COMMENT_UPDATES} SET publishedToPostUpdatesMFS = 1 WHERE cid IN (${placeholders})`);
|
|
4031
4047
|
}
|
|
4048
|
+
queryPublishedPostCidsOfBucket(bucket) {
|
|
4049
|
+
return this._db.prepare(`SELECT cid FROM ${TABLES.COMMENT_UPDATES} WHERE postUpdatesBucket = ? AND publishedToPostUpdatesMFS = 1`).pluck().all(bucket);
|
|
4050
|
+
}
|
|
4032
4051
|
forceUpdateOnAllComments() {
|
|
4033
4052
|
this._db.prepare(`UPDATE ${TABLES.COMMENT_UPDATES} SET publishedToPostUpdatesMFS = 0`).run();
|
|
4034
4053
|
}
|
|
@@ -4447,6 +4466,58 @@ async function statMfsPathOrUndefined(kuboRpcClient, path, log) {
|
|
|
4447
4466
|
throw error;
|
|
4448
4467
|
}
|
|
4449
4468
|
}
|
|
4469
|
+
const bucketOfPath = (bucketPath) => Number(bucketPath.split("/").pop());
|
|
4470
|
+
async function markPostsMissingFromBucketForRewrite({ community, bucket, log }) {
|
|
4471
|
+
const published = community._dbHandler.queryPublishedPostCidsOfBucket(bucket);
|
|
4472
|
+
if (published.length === 0) return 0;
|
|
4473
|
+
const kubo = community._clientsManager.getDefaultKuboRpcClient()._client;
|
|
4474
|
+
const listed = /* @__PURE__ */ new Set();
|
|
4475
|
+
try {
|
|
4476
|
+
for await (const entry of kubo.files.ls(`/${community.address}/postUpdates/${bucket}`, { timeout: MFS_OP_TIMEOUT_MS })) listed.add(entry.name);
|
|
4477
|
+
} catch (error) {
|
|
4478
|
+
if (!isAbsentPathError(error)) throw error;
|
|
4479
|
+
}
|
|
4480
|
+
const missing = published.filter((cid) => !listed.has(cid));
|
|
4481
|
+
if (missing.length > 0) {
|
|
4482
|
+
community._dbHandler.forceUpdateOnAllCommentsWithCid(missing);
|
|
4483
|
+
log.error(`The postUpdates bucket ${bucket} of community ${community.address} holds ${listed.size} entries in MFS and ${missing.length} of its ${published.length} published posts are not in it. They will be written again by the next cycle`);
|
|
4484
|
+
}
|
|
4485
|
+
return missing.length;
|
|
4486
|
+
}
|
|
4487
|
+
const bucketsOfPaths = (community, mfsPaths) => {
|
|
4488
|
+
const prefix = `/${community.address}/postUpdates/`;
|
|
4489
|
+
const buckets = /* @__PURE__ */ new Set();
|
|
4490
|
+
for (const path of mfsPaths) if (path.startsWith(prefix)) {
|
|
4491
|
+
const bucket = Number(path.slice(prefix.length).split("/")[0]);
|
|
4492
|
+
if (Number.isFinite(bucket)) buckets.add(bucket);
|
|
4493
|
+
}
|
|
4494
|
+
return [...buckets];
|
|
4495
|
+
};
|
|
4496
|
+
async function statBucketsOfPaths({ community, mfsPaths }) {
|
|
4497
|
+
const log = logger_default("pkc-js:local-community:sync:statBucketsOfPaths");
|
|
4498
|
+
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
4499
|
+
const stats = /* @__PURE__ */ new Map();
|
|
4500
|
+
for (const bucket of bucketsOfPaths(community, mfsPaths)) stats.set(bucket, await statMfsPathOrUndefined(kuboRpcClient, `/${community.address}/postUpdates/${bucket}`, log).then((stat) => stat?.cid.toString(), () => null));
|
|
4501
|
+
return stats;
|
|
4502
|
+
}
|
|
4503
|
+
function noteUnconfirmedRemovalsFromBuckets({ community, mfsPaths }) {
|
|
4504
|
+
for (const bucket of bucketsOfPaths(community, mfsPaths)) community._postUpdatesBucketsWithUnconfirmedRemovals.add(bucket);
|
|
4505
|
+
}
|
|
4506
|
+
async function rememberPostUpdatesBucketsOfPaths({ community, mfsPaths, before }) {
|
|
4507
|
+
const log = logger_default("pkc-js:local-community:sync:rememberPostUpdatesBuckets");
|
|
4508
|
+
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
4509
|
+
for (const bucket of bucketsOfPaths(community, mfsPaths)) {
|
|
4510
|
+
const remembered = community._postUpdatesBucketCids.get(bucket);
|
|
4511
|
+
if (remembered !== void 0 && before.get(bucket) !== remembered) {
|
|
4512
|
+
community._postUpdatesBucketsWithUnconfirmedRemovals.add(bucket);
|
|
4513
|
+
continue;
|
|
4514
|
+
}
|
|
4515
|
+
community._postUpdatesBucketsWithUnconfirmedRemovals.delete(bucket);
|
|
4516
|
+
const stat = await statMfsPathOrUndefined(kuboRpcClient, `/${community.address}/postUpdates/${bucket}`, log).catch(() => void 0);
|
|
4517
|
+
if (stat) community._postUpdatesBucketCids.set(bucket, stat.cid.toString());
|
|
4518
|
+
else community._postUpdatesBucketCids.delete(bucket);
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4450
4521
|
async function buildPostUpdateFiles(posts) {
|
|
4451
4522
|
const { importer } = await import("./src-DIOHVUq9.js");
|
|
4452
4523
|
const blocks = /* @__PURE__ */ new Map();
|
|
@@ -4561,22 +4632,68 @@ async function writePostUpdatesToBucket({ community, bucketPath, posts }) {
|
|
|
4561
4632
|
}
|
|
4562
4633
|
return bytes;
|
|
4563
4634
|
};
|
|
4635
|
+
const bucket = bucketOfPath(bucketPath);
|
|
4564
4636
|
let live = await recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log);
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4637
|
+
if (!live) {
|
|
4638
|
+
const bucketWasHere = community._postUpdatesBucketCids.delete(bucket);
|
|
4639
|
+
await markPostsMissingFromBucketForRewrite({
|
|
4640
|
+
community,
|
|
4641
|
+
bucket,
|
|
4642
|
+
log
|
|
4643
|
+
});
|
|
4644
|
+
if (bucketWasHere) throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4569
4645
|
communityAddress: community.address,
|
|
4570
4646
|
bucketPath,
|
|
4571
|
-
attempt
|
|
4647
|
+
attempt: 0
|
|
4572
4648
|
});
|
|
4649
|
+
}
|
|
4650
|
+
const rememberedCid = community._postUpdatesBucketCids.get(bucket);
|
|
4651
|
+
const pendingCid = community._postUpdatesBucketPendingCids.get(bucket);
|
|
4652
|
+
if (live && pendingCid !== void 0 && live.cid.toString() === pendingCid) {
|
|
4653
|
+
community._postUpdatesBucketCids.set(bucket, pendingCid);
|
|
4654
|
+
community._postUpdatesBucketPendingCids.delete(bucket);
|
|
4655
|
+
} else if (live && rememberedCid !== void 0 && rememberedCid !== live.cid.toString()) {
|
|
4656
|
+
const missing = await markPostsMissingFromBucketForRewrite({
|
|
4657
|
+
community,
|
|
4658
|
+
bucket,
|
|
4659
|
+
log
|
|
4660
|
+
});
|
|
4661
|
+
const removalsExplainIt = community._postUpdatesBucketsWithUnconfirmedRemovals.delete(bucket);
|
|
4662
|
+
community._postUpdatesBucketCids.set(bucket, live.cid.toString());
|
|
4663
|
+
if (!(removalsExplainIt && missing === 0)) throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4664
|
+
communityAddress: community.address,
|
|
4665
|
+
bucketPath,
|
|
4666
|
+
attempt: 0,
|
|
4667
|
+
bucketCidInMfs: live.cid.toString(),
|
|
4668
|
+
bucketCidRemembered: rememberedCid
|
|
4669
|
+
});
|
|
4670
|
+
}
|
|
4671
|
+
let bucketExisted = false;
|
|
4672
|
+
for (let attempt = 1;; attempt++) {
|
|
4673
|
+
if (live) bucketExisted = true;
|
|
4674
|
+
else if (bucketExisted) {
|
|
4675
|
+
community._postUpdatesBucketCids.delete(bucket);
|
|
4676
|
+
await markPostsMissingFromBucketForRewrite({
|
|
4677
|
+
community,
|
|
4678
|
+
bucket,
|
|
4679
|
+
log
|
|
4680
|
+
});
|
|
4681
|
+
throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4682
|
+
communityAddress: community.address,
|
|
4683
|
+
bucketPath,
|
|
4684
|
+
attempt
|
|
4685
|
+
});
|
|
4686
|
+
}
|
|
4573
4687
|
const { cid: root, newBlocks } = await patchUnixFsDirectory({
|
|
4574
4688
|
directoryCid: live?.cid,
|
|
4575
4689
|
entriesToPut: entries,
|
|
4576
4690
|
getBlock,
|
|
4577
4691
|
shardSplitThresholdBytes: MFS_SHARD_SPLIT_THRESHOLD_BYTES
|
|
4578
4692
|
});
|
|
4579
|
-
if (live && root.equals(live.cid))
|
|
4693
|
+
if (live && root.equals(live.cid)) {
|
|
4694
|
+
community._postUpdatesBucketCids.set(bucket, live.cid.toString());
|
|
4695
|
+
return;
|
|
4696
|
+
}
|
|
4580
4697
|
if (attempt > MAX_ATTEMPTS_TO_SWAP_POST_UPDATES_BUCKET) throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4581
4698
|
communityAddress: community.address,
|
|
4582
4699
|
bucketPath,
|
|
@@ -4600,6 +4717,7 @@ async function writePostUpdatesToBucket({ community, bucketPath, posts }) {
|
|
|
4600
4717
|
timeout: MFS_OP_TIMEOUT_MS
|
|
4601
4718
|
})) if (result.root.pinErrorMsg) throw Error(`Failed to pin the new blocks of bucket ${bucketPath} (${result.root.cid.toString()}): ${result.root.pinErrorMsg}`);
|
|
4602
4719
|
log(`Bucket ${bucketPath}: ${posts.length} posts written, ${newBlocks.length} of the bucket's nodes rebuilt (${car.length} bytes imported), root ${root.toString()}`);
|
|
4720
|
+
community._postUpdatesBucketPendingCids.set(bucket, root.toString());
|
|
4603
4721
|
await kubo.files.cp(`/ipfs/${root.toString()}`, nextPath, {
|
|
4604
4722
|
parents: true,
|
|
4605
4723
|
flush: true,
|
|
@@ -4619,9 +4737,30 @@ async function writePostUpdatesToBucket({ community, bucketPath, posts }) {
|
|
|
4619
4737
|
});
|
|
4620
4738
|
}
|
|
4621
4739
|
const swapped = await statMfsPathOrUndefined(kuboRpcClient, bucketPath, log);
|
|
4622
|
-
if (swapped?.cid.equals(root))
|
|
4740
|
+
if (swapped?.cid.equals(root)) {
|
|
4741
|
+
community._postUpdatesBucketCids.set(bucket, root.toString());
|
|
4742
|
+
community._postUpdatesBucketPendingCids.delete(bucket);
|
|
4743
|
+
return;
|
|
4744
|
+
}
|
|
4623
4745
|
log.error(`Bucket ${bucketPath} is ${swapped?.cid.toString()} in MFS after ${root.toString()} was swapped in (attempt ${attempt}), checking it for the posts' files`);
|
|
4624
4746
|
live = await recoverInterruptedBucketSwap(kuboRpcClient, bucketPath, log);
|
|
4747
|
+
if (live) {
|
|
4748
|
+
if (await markPostsMissingFromBucketForRewrite({
|
|
4749
|
+
community,
|
|
4750
|
+
bucket,
|
|
4751
|
+
log
|
|
4752
|
+
}) > 0) {
|
|
4753
|
+
community._postUpdatesBucketCids.set(bucket, live.cid.toString());
|
|
4754
|
+
community._postUpdatesBucketPendingCids.delete(bucket);
|
|
4755
|
+
throw new PKCError("ERR_POST_UPDATES_BUCKET_SWAP_WAS_LOST", {
|
|
4756
|
+
communityAddress: community.address,
|
|
4757
|
+
bucketPath,
|
|
4758
|
+
attempt,
|
|
4759
|
+
bucketCidInMfs: live.cid.toString(),
|
|
4760
|
+
bucketCidWithThePosts: root.toString()
|
|
4761
|
+
});
|
|
4762
|
+
}
|
|
4763
|
+
}
|
|
4625
4764
|
}
|
|
4626
4765
|
}
|
|
4627
4766
|
//#endregion
|
|
@@ -4931,6 +5070,10 @@ async function rmUnneededMfsPaths(community, opts) {
|
|
|
4931
5070
|
const toDeleteMfsPaths = Array.from(community._mfsPathsToRemove.values());
|
|
4932
5071
|
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
4933
5072
|
for (const watcher of community._mfsPathRemovalWatchers) for (const path of toDeleteMfsPaths) watcher.add(path);
|
|
5073
|
+
const bucketsBefore = await statBucketsOfPaths({
|
|
5074
|
+
community,
|
|
5075
|
+
mfsPaths: toDeleteMfsPaths
|
|
5076
|
+
});
|
|
4934
5077
|
try {
|
|
4935
5078
|
await removeMfsFilesSafely({
|
|
4936
5079
|
kuboRpcClient: kuboRpc,
|
|
@@ -4939,14 +5082,28 @@ async function rmUnneededMfsPaths(community, opts) {
|
|
|
4939
5082
|
inputNumOfRetries: opts?.numOfRetries
|
|
4940
5083
|
});
|
|
4941
5084
|
toDeleteMfsPaths.forEach((path) => community._mfsPathsToRemove.delete(path));
|
|
5085
|
+
await rememberPostUpdatesBucketsOfPaths({
|
|
5086
|
+
community,
|
|
5087
|
+
mfsPaths: toDeleteMfsPaths,
|
|
5088
|
+
before: bucketsBefore
|
|
5089
|
+
});
|
|
4942
5090
|
return toDeleteMfsPaths;
|
|
4943
5091
|
} catch (e) {
|
|
4944
5092
|
const error = e;
|
|
4945
5093
|
if (error.message.includes("file does not exist")) {
|
|
4946
5094
|
toDeleteMfsPaths.forEach((path) => community._mfsPathsToRemove.delete(path));
|
|
5095
|
+
await rememberPostUpdatesBucketsOfPaths({
|
|
5096
|
+
community,
|
|
5097
|
+
mfsPaths: toDeleteMfsPaths,
|
|
5098
|
+
before: bucketsBefore
|
|
5099
|
+
});
|
|
4947
5100
|
return toDeleteMfsPaths;
|
|
4948
5101
|
} else {
|
|
4949
5102
|
log.error("Failed to remove paths from MFS", toDeleteMfsPaths, e);
|
|
5103
|
+
noteUnconfirmedRemovalsFromBuckets({
|
|
5104
|
+
community,
|
|
5105
|
+
mfsPaths: toDeleteMfsPaths
|
|
5106
|
+
});
|
|
4950
5107
|
throw error;
|
|
4951
5108
|
}
|
|
4952
5109
|
}
|
|
@@ -6523,22 +6680,26 @@ async function storePublication({ community, request, pendingApproval, challenge
|
|
|
6523
6680
|
}
|
|
6524
6681
|
//#endregion
|
|
6525
6682
|
//#region dist/node/runtime/node/community/local-community/pubsub.js
|
|
6683
|
+
const SHARED_TOPIC_LIST_MAX_AGE_AS_FRACTION_OF_PUBLISH_INTERVAL = 1 / 4;
|
|
6526
6684
|
async function listenToIncomingRequests(community) {
|
|
6527
6685
|
const log = logger_default("pkc-js:local-community:sync:_listenToIncomingRequests");
|
|
6528
6686
|
const topic = challengeExchangePubsubTopic(community);
|
|
6529
6687
|
const pubsubClient = topic ? community._clientsManager.getDefaultKuboPubsubClient() : community._clientsManager.getDefaultKuboPubsubClientIfAny();
|
|
6530
6688
|
if (!pubsubClient) return;
|
|
6531
|
-
const subscribedTopics = await
|
|
6689
|
+
const subscribedTopics = await listSubscribedPubsubTopicsShared({
|
|
6690
|
+
client: pubsubClient._client,
|
|
6691
|
+
maxAgeMs: community._pkc.publishInterval * SHARED_TOPIC_LIST_MAX_AGE_AS_FRACTION_OF_PUBLISH_INTERVAL
|
|
6692
|
+
});
|
|
6532
6693
|
const staleTopic = community._subscribedChallengePubsubTopic;
|
|
6533
6694
|
const unsubscribeStaleTopicIfNeeded = async (currentTopic) => {
|
|
6534
6695
|
if (!staleTopic || staleTopic === currentTopic) return;
|
|
6535
|
-
if (subscribedTopics.
|
|
6696
|
+
if (subscribedTopics.has(staleTopic)) await community._clientsManager.pubsubUnsubscribe(staleTopic, community.handleChallengeExchange);
|
|
6536
6697
|
community._subscribedChallengePubsubTopic = void 0;
|
|
6537
6698
|
log(`Stopped listening on the previous challenge exchange pubsub topic (${staleTopic})`);
|
|
6538
6699
|
};
|
|
6539
6700
|
if (!topic) {
|
|
6540
6701
|
const disabledTopic = communityChallengePubsubTopic(community);
|
|
6541
|
-
if (disabledTopic && subscribedTopics.
|
|
6702
|
+
if (disabledTopic && subscribedTopics.has(disabledTopic)) {
|
|
6542
6703
|
await community._clientsManager.pubsubUnsubscribe(disabledTopic, community.handleChallengeExchange);
|
|
6543
6704
|
if (community._subscribedChallengePubsubTopic === disabledTopic) community._subscribedChallengePubsubTopic = void 0;
|
|
6544
6705
|
log(`Challenge exchange is disabled, unsubscribed from pubsub topic (${disabledTopic})`);
|
|
@@ -6547,7 +6708,7 @@ async function listenToIncomingRequests(community) {
|
|
|
6547
6708
|
return;
|
|
6548
6709
|
}
|
|
6549
6710
|
await unsubscribeStaleTopicIfNeeded(topic);
|
|
6550
|
-
if (!subscribedTopics.
|
|
6711
|
+
if (!subscribedTopics.has(topic)) {
|
|
6551
6712
|
await community._clientsManager.pubsubUnsubscribe(topic, community.handleChallengeExchange);
|
|
6552
6713
|
await community._clientsManager.pubsubSubscribe(topic, community.handleChallengeExchange);
|
|
6553
6714
|
community._clientsManager.updateKuboRpcPubsubState("waiting-challenge-requests", pubsubClient.url);
|
|
@@ -6662,18 +6823,47 @@ async function syncWithRegistries(community) {
|
|
|
6662
6823
|
async function calculateNewPostUpdates(community) {
|
|
6663
6824
|
const postUpdates = {};
|
|
6664
6825
|
const kuboRpcClient = community._clientsManager.getDefaultKuboRpcClient();
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6826
|
+
const log = logger_default("pkc-js:local-community:sync:calculateNewPostUpdates");
|
|
6827
|
+
for (const timeBucket of community._postUpdatesBuckets) {
|
|
6828
|
+
const rememberedCid = community._postUpdatesBucketCids.get(timeBucket);
|
|
6829
|
+
let cidInMfs;
|
|
6830
|
+
let absent = false;
|
|
6831
|
+
try {
|
|
6832
|
+
const statRes = await statMfsPathSafely({
|
|
6833
|
+
kuboRpcClient,
|
|
6834
|
+
path: `/${community.address}/postUpdates/${timeBucket}`
|
|
6835
|
+
});
|
|
6836
|
+
cidInMfs = String(statRes.cid);
|
|
6837
|
+
if (statRes.blocks !== 0) postUpdates[String(timeBucket)] = cidInMfs;
|
|
6838
|
+
} catch (error) {
|
|
6839
|
+
if (!isAbsentPathError(error)) continue;
|
|
6840
|
+
absent = true;
|
|
6841
|
+
}
|
|
6842
|
+
const lost = absent && (rememberedCid !== void 0 || community.postUpdates?.[String(timeBucket)] !== void 0);
|
|
6843
|
+
const changed = !absent && rememberedCid !== void 0 && rememberedCid !== cidInMfs;
|
|
6844
|
+
if (lost || changed) try {
|
|
6845
|
+
await markPostsMissingFromBucketForRewrite({
|
|
6846
|
+
community,
|
|
6847
|
+
bucket: timeBucket,
|
|
6848
|
+
log
|
|
6849
|
+
});
|
|
6850
|
+
} catch (error) {
|
|
6851
|
+
log.error(`Failed to check the postUpdates bucket ${timeBucket} of community ${community.address}`, error);
|
|
6852
|
+
continue;
|
|
6853
|
+
}
|
|
6854
|
+
if (lost || changed) community._postUpdatesBucketsWithUnconfirmedRemovals.delete(timeBucket);
|
|
6855
|
+
if (cidInMfs !== void 0) community._postUpdatesBucketCids.set(timeBucket, cidInMfs);
|
|
6856
|
+
else community._postUpdatesBucketCids.delete(timeBucket);
|
|
6857
|
+
}
|
|
6672
6858
|
if (e(postUpdates)) return void 0;
|
|
6673
6859
|
return postUpdates;
|
|
6674
6860
|
}
|
|
6861
|
+
const MAX_SECONDS_BETWEEN_COMMUNITY_RECORDS = 900;
|
|
6862
|
+
function msUntilLastPublishIsTooOld(community) {
|
|
6863
|
+
return ((community.updatedAt || 0) + MAX_SECONDS_BETWEEN_COMMUNITY_RECORDS) * 1e3 + 500 - Date.now();
|
|
6864
|
+
}
|
|
6675
6865
|
function calculateLatestUpdateTrigger(community) {
|
|
6676
|
-
const lastPublishTooOld = (community.updatedAt || 0) < timestamp() -
|
|
6866
|
+
const lastPublishTooOld = (community.updatedAt || 0) < timestamp() - MAX_SECONDS_BETWEEN_COMMUNITY_RECORDS;
|
|
6677
6867
|
const lastPostCidChanged = community.lastPostCid !== community._dbHandler.queryLatestPostCid()?.cid;
|
|
6678
6868
|
const lastCommentCidChanged = community.lastCommentCid !== community._dbHandler.queryLatestCommentCid()?.cid;
|
|
6679
6869
|
if (!community._communityUpdateTrigger && (lastPublishTooOld || community._pendingEditProps.length > 0 || community._blocksToRm.length > 0 || lastCommentCidChanged || lastPostCidChanged)) community._communityUpdateTrigger = true;
|
|
@@ -6916,23 +7106,58 @@ async function updateCommunityIpnsIfNeeded(community, cidsUpdatedInThisCycle) {
|
|
|
6916
7106
|
throw e;
|
|
6917
7107
|
}
|
|
6918
7108
|
}
|
|
7109
|
+
function slowCycleReport({ cycleMs, slowAfterMs, phasesMs }) {
|
|
7110
|
+
if (cycleMs <= slowAfterMs) return void 0;
|
|
7111
|
+
const phases = Object.entries(phasesMs).filter(([, ms]) => ms > 0).sort(([, a], [, b]) => b - a).map(([phase, ms]) => `${phase} ${ms}ms`);
|
|
7112
|
+
return `took ${Math.round(cycleMs)}ms, longer than the publish interval of ${slowAfterMs}ms: ${phases.join(", ")}`;
|
|
7113
|
+
}
|
|
7114
|
+
function reportCycleIfSlow({ community, cycleMs, phasesMs, log }) {
|
|
7115
|
+
const report = slowCycleReport({
|
|
7116
|
+
cycleMs,
|
|
7117
|
+
slowAfterMs: community._pkc.publishInterval,
|
|
7118
|
+
phasesMs
|
|
7119
|
+
});
|
|
7120
|
+
if (report) log.error(`A publish cycle of community`, community.address, report);
|
|
7121
|
+
}
|
|
6919
7122
|
async function syncIpnsWithDb(community) {
|
|
6920
7123
|
const log = logger_default("pkc-js:local-community:sync");
|
|
6921
7124
|
const kuboRpc = community._clientsManager.getDefaultKuboRpcClient();
|
|
7125
|
+
const cycleStartedAtMs = performance.now();
|
|
7126
|
+
const phasesMs = {};
|
|
7127
|
+
const timed = async (phase, run) => {
|
|
7128
|
+
const phaseStartedAtMs = performance.now();
|
|
7129
|
+
try {
|
|
7130
|
+
return await run();
|
|
7131
|
+
} finally {
|
|
7132
|
+
phasesMs[phase] = Math.round(performance.now() - phaseStartedAtMs);
|
|
7133
|
+
}
|
|
7134
|
+
};
|
|
6922
7135
|
try {
|
|
6923
|
-
await community._listenToIncomingRequests();
|
|
6924
|
-
await providePubsubTopicRoutingCidsIfNeeded(community);
|
|
6925
|
-
await adjustPostUpdatesBucketsIfNeeded(community);
|
|
7136
|
+
await timed("listenToIncomingRequests", () => community._listenToIncomingRequests());
|
|
7137
|
+
await timed("providePubsubTopicRoutingCids", () => providePubsubTopicRoutingCidsIfNeeded(community));
|
|
7138
|
+
await timed("adjustPostUpdatesBuckets", () => adjustPostUpdatesBucketsIfNeeded(community));
|
|
6926
7139
|
community._setStartedStateWithEmission("publishing-ipns");
|
|
6927
7140
|
community._clientsManager.updateKuboRpcState("publishing-ipns", kuboRpc.url);
|
|
6928
|
-
await purgeDisapprovedCommentsOlderThan(community);
|
|
6929
|
-
await syncWithRegistries(community);
|
|
6930
|
-
const cidsUpdatedInThisCycle = await updateCommentsAndWritePostUpdates(community);
|
|
6931
|
-
if (community._mfsPathsToRemove.size > 0) await rmUnneededMfsPaths(community);
|
|
7141
|
+
await timed("purgeDisapprovedComments", () => purgeDisapprovedCommentsOlderThan(community));
|
|
7142
|
+
await timed("syncWithRegistries", () => syncWithRegistries(community));
|
|
7143
|
+
const cidsUpdatedInThisCycle = await timed("updateCommentsAndWritePostUpdates", () => updateCommentsAndWritePostUpdates(community));
|
|
7144
|
+
if (community._mfsPathsToRemove.size > 0) await timed("rmUnneededMfsPaths", () => rmUnneededMfsPaths(community));
|
|
6932
7145
|
requireCommunityUpdateIfModQueueChanged(community);
|
|
6933
|
-
await updateCommunityIpnsIfNeeded(community, cidsUpdatedInThisCycle);
|
|
6934
|
-
await cleanUpIpfsRepoIfDue(community);
|
|
7146
|
+
await timed("updateCommunityIpns", () => updateCommunityIpnsIfNeeded(community, cidsUpdatedInThisCycle));
|
|
7147
|
+
await timed("cleanUpIpfsRepo", () => cleanUpIpfsRepoIfDue(community));
|
|
7148
|
+
reportCycleIfSlow({
|
|
7149
|
+
community,
|
|
7150
|
+
cycleMs: performance.now() - cycleStartedAtMs,
|
|
7151
|
+
phasesMs,
|
|
7152
|
+
log
|
|
7153
|
+
});
|
|
6935
7154
|
} catch (e) {
|
|
7155
|
+
reportCycleIfSlow({
|
|
7156
|
+
community,
|
|
7157
|
+
cycleMs: performance.now() - cycleStartedAtMs,
|
|
7158
|
+
phasesMs,
|
|
7159
|
+
log
|
|
7160
|
+
});
|
|
6936
7161
|
e.details = {
|
|
6937
7162
|
...e.details,
|
|
6938
7163
|
communityAddress: community.address
|
|
@@ -6944,6 +7169,51 @@ async function syncIpnsWithDb(community) {
|
|
|
6944
7169
|
throw e;
|
|
6945
7170
|
}
|
|
6946
7171
|
}
|
|
7172
|
+
const EVENT_LOOP_CHECK_PERIOD_MS = 1e4;
|
|
7173
|
+
const EVENT_LOOP_DELAY_RESOLUTION_MS = 20;
|
|
7174
|
+
let watch$1;
|
|
7175
|
+
function eventLoopDelayToReport({ maxNs, p99Ns, resolutionMs = EVENT_LOOP_DELAY_RESOLUTION_MS, reportMs = 200 }) {
|
|
7176
|
+
const maxLateMs = Math.round(maxNs / 1e6 - resolutionMs);
|
|
7177
|
+
if (maxLateMs < reportMs) return void 0;
|
|
7178
|
+
return {
|
|
7179
|
+
maxLateMs,
|
|
7180
|
+
p99LateMs: Math.max(0, Math.round(p99Ns / 1e6 - resolutionMs))
|
|
7181
|
+
};
|
|
7182
|
+
}
|
|
7183
|
+
function holdEventLoopWatch() {
|
|
7184
|
+
if (!watch$1) {
|
|
7185
|
+
const log = logger_default("pkc-js:event-loop-watch");
|
|
7186
|
+
const histogram = monitorEventLoopDelay({ resolution: EVENT_LOOP_DELAY_RESOLUTION_MS });
|
|
7187
|
+
histogram.enable();
|
|
7188
|
+
const checkTimer = setInterval(() => {
|
|
7189
|
+
const report = eventLoopDelayToReport({
|
|
7190
|
+
maxNs: histogram.max,
|
|
7191
|
+
p99Ns: histogram.percentile(99)
|
|
7192
|
+
});
|
|
7193
|
+
histogram.reset();
|
|
7194
|
+
if (report) log.error(`The main thread was blocked for up to ${report.maxLateMs}ms in the last ${EVENT_LOOP_CHECK_PERIOD_MS / 1e3}s (99% of timers were at most ${report.p99LateMs}ms late). Everything this process does waited that long.`);
|
|
7195
|
+
}, EVENT_LOOP_CHECK_PERIOD_MS);
|
|
7196
|
+
checkTimer.unref();
|
|
7197
|
+
watch$1 = {
|
|
7198
|
+
histogram,
|
|
7199
|
+
checkTimer,
|
|
7200
|
+
holders: 0
|
|
7201
|
+
};
|
|
7202
|
+
}
|
|
7203
|
+
watch$1.holders++;
|
|
7204
|
+
let released = false;
|
|
7205
|
+
return () => {
|
|
7206
|
+
if (released || !watch$1) return;
|
|
7207
|
+
released = true;
|
|
7208
|
+
if (--watch$1.holders > 0) return;
|
|
7209
|
+
clearInterval(watch$1.checkTimer);
|
|
7210
|
+
watch$1.histogram.disable();
|
|
7211
|
+
watch$1 = void 0;
|
|
7212
|
+
};
|
|
7213
|
+
}
|
|
7214
|
+
//#endregion
|
|
7215
|
+
//#region dist/node/runtime/node/community/local-community/reprovide-on-address-change.js
|
|
7216
|
+
const ADDRESS_REPROVIDE_POLL_INTERVAL_MS = 60 * 1e3;
|
|
6947
7217
|
function normalizeSelfAddrsForProvider(addrs, peerId) {
|
|
6948
7218
|
const suffix = `/p2p/${peerId}`;
|
|
6949
7219
|
return n$3(addrs.map((addr) => addr.endsWith(suffix) ? addr.slice(0, -suffix.length) : addr));
|
|
@@ -6951,12 +7221,34 @@ function normalizeSelfAddrsForProvider(addrs, peerId) {
|
|
|
6951
7221
|
function isBrowserDialableAddr(addr) {
|
|
6952
7222
|
return addr.includes("/webrtc") || addr.includes("/ws") || addr.includes("/webtransport") && addr.includes("/certhash/");
|
|
6953
7223
|
}
|
|
6954
|
-
async function getBrowserDialableSelfAddrs(client) {
|
|
6955
|
-
const idRes = await client.id();
|
|
7224
|
+
async function getBrowserDialableSelfAddrs(client, options) {
|
|
7225
|
+
const idRes = await client.id(options);
|
|
6956
7226
|
const peerId = idRes.id.toString();
|
|
6957
|
-
const swarmListeningAddresses = (await client.swarm.addrs()).filter((swarmAddr) => swarmAddr.id.toString() === peerId);
|
|
7227
|
+
const swarmListeningAddresses = (await client.swarm.addrs(options)).filter((swarmAddr) => swarmAddr.id.toString() === peerId);
|
|
6958
7228
|
return n$3(normalizeSelfAddrsForProvider([...idRes.addresses.map((addr) => addr.toString()), ...n$5(swarmListeningAddresses.map((swarmAddr) => swarmAddr.addrs.map((addr) => addr.toString())))], peerId).filter(isBrowserDialableAddr)).sort();
|
|
6959
7229
|
}
|
|
7230
|
+
const sharedSelfAddrsByClient = /* @__PURE__ */ new WeakMap();
|
|
7231
|
+
async function getBrowserDialableSelfAddrsShared({ client, maxAgeMs }) {
|
|
7232
|
+
let shared = sharedSelfAddrsByClient.get(client);
|
|
7233
|
+
if (!shared) {
|
|
7234
|
+
shared = {};
|
|
7235
|
+
sharedSelfAddrsByClient.set(client, shared);
|
|
7236
|
+
}
|
|
7237
|
+
const sharedOfClient = shared;
|
|
7238
|
+
if (sharedOfClient.stored && Date.now() - sharedOfClient.stored.readAtMs < maxAgeMs) return sharedOfClient.stored;
|
|
7239
|
+
if (sharedOfClient.inFlight) return sharedOfClient.inFlight;
|
|
7240
|
+
const inFlight = getBrowserDialableSelfAddrs(client, { timeout: SHARED_KUBO_READ_TIMEOUT_MS }).then((addrs) => {
|
|
7241
|
+
sharedOfClient.stored = {
|
|
7242
|
+
addrs,
|
|
7243
|
+
readAtMs: Date.now()
|
|
7244
|
+
};
|
|
7245
|
+
return sharedOfClient.stored;
|
|
7246
|
+
}).finally(() => {
|
|
7247
|
+
if (sharedOfClient.inFlight === inFlight) sharedOfClient.inFlight = void 0;
|
|
7248
|
+
});
|
|
7249
|
+
sharedOfClient.inFlight = inFlight;
|
|
7250
|
+
return inFlight;
|
|
7251
|
+
}
|
|
6960
7252
|
function connectionCriticalCids(community) {
|
|
6961
7253
|
return n$3([community.pubsubTopicRoutingCid, community.ipnsPubsubTopicRoutingCid].filter((cid) => typeof cid === "string"));
|
|
6962
7254
|
}
|
|
@@ -6968,23 +7260,31 @@ function connectionCriticalCids(community) {
|
|
|
6968
7260
|
* The first observation only establishes a baseline (start() already force-provides these CIDs with fresh
|
|
6969
7261
|
* addresses via providePubsubTopicRoutingCidsIfNeeded); subsequent changes trigger a re-provide.
|
|
6970
7262
|
*/
|
|
6971
|
-
async function reprovideConnectionCidsIfBrowserAddrsChanged(community) {
|
|
7263
|
+
async function reprovideConnectionCidsIfBrowserAddrsChanged(community, { selfAddrsMaxAgeMs = 0 } = {}) {
|
|
6972
7264
|
const log = logger_default("pkc-js:local-community:_reprovideConnectionCidsIfBrowserAddrsChanged");
|
|
6973
7265
|
const client = community._clientsManager.getDefaultKuboRpcClient()._client;
|
|
6974
|
-
const current = await
|
|
7266
|
+
const { addrs: current, readAtMs: browserAddrsReadAtMs } = selfAddrsMaxAgeMs > 0 ? await getBrowserDialableSelfAddrsShared({
|
|
7267
|
+
client,
|
|
7268
|
+
maxAgeMs: selfAddrsMaxAgeMs
|
|
7269
|
+
}) : {
|
|
7270
|
+
addrs: await getBrowserDialableSelfAddrs(client),
|
|
7271
|
+
readAtMs: Date.now()
|
|
7272
|
+
};
|
|
6975
7273
|
const previous = community._lastProvidedBrowserDialableSelfAddrs;
|
|
6976
7274
|
if (previous === void 0) {
|
|
6977
7275
|
community._lastProvidedBrowserDialableSelfAddrs = current;
|
|
6978
7276
|
return {
|
|
6979
7277
|
reprovided: false,
|
|
6980
7278
|
providedCids: [],
|
|
6981
|
-
browserAddrs: current
|
|
7279
|
+
browserAddrs: current,
|
|
7280
|
+
browserAddrsReadAtMs
|
|
6982
7281
|
};
|
|
6983
7282
|
}
|
|
6984
7283
|
if (t$8(previous, current)) return {
|
|
6985
7284
|
reprovided: false,
|
|
6986
7285
|
providedCids: [],
|
|
6987
|
-
browserAddrs: current
|
|
7286
|
+
browserAddrs: current,
|
|
7287
|
+
browserAddrsReadAtMs
|
|
6988
7288
|
};
|
|
6989
7289
|
community._lastProvidedBrowserDialableSelfAddrs = current;
|
|
6990
7290
|
const cidStrings = connectionCriticalCids(community);
|
|
@@ -7009,7 +7309,8 @@ async function reprovideConnectionCidsIfBrowserAddrsChanged(community) {
|
|
|
7009
7309
|
return {
|
|
7010
7310
|
reprovided: providedCids.length > 0,
|
|
7011
7311
|
providedCids,
|
|
7012
|
-
browserAddrs: current
|
|
7312
|
+
browserAddrs: current,
|
|
7313
|
+
browserAddrsReadAtMs
|
|
7013
7314
|
};
|
|
7014
7315
|
}
|
|
7015
7316
|
/**
|
|
@@ -7021,10 +7322,12 @@ async function reprovideOnAddressChangeIfDue(community) {
|
|
|
7021
7322
|
const now = Date.now();
|
|
7022
7323
|
if (typeof community._lastAddressReprovideCheckAt === "number" && now - community._lastAddressReprovideCheckAt < 6e4) return;
|
|
7023
7324
|
community._lastAddressReprovideCheckAt = now;
|
|
7024
|
-
await reprovideConnectionCidsIfBrowserAddrsChanged(community);
|
|
7325
|
+
const { browserAddrsReadAtMs } = await reprovideConnectionCidsIfBrowserAddrsChanged(community, { selfAddrsMaxAgeMs: ADDRESS_REPROVIDE_POLL_INTERVAL_MS / 4 });
|
|
7326
|
+
community._lastAddressReprovideCheckAt = Math.min(now, browserAddrsReadAtMs);
|
|
7025
7327
|
}
|
|
7026
7328
|
//#endregion
|
|
7027
7329
|
//#region dist/node/runtime/node/community/local-community/lifecycle.js
|
|
7330
|
+
const MIN_MS_BETWEEN_PUBLISH_CYCLES = 100;
|
|
7028
7331
|
async function publishLoop(community, syncIntervalMs) {
|
|
7029
7332
|
const log = logger_default("pkc-js:local-community:_publishLoop");
|
|
7030
7333
|
let syncFailedSinceStop = false;
|
|
@@ -7032,50 +7335,67 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
7032
7335
|
return community.state !== "started" || community._stopHasBeenCalled && (community._pendingEditProps.length === 0 || syncFailedSinceStop);
|
|
7033
7336
|
};
|
|
7034
7337
|
const waitUntilNextSync = async ({ lastSyncFailed }) => {
|
|
7035
|
-
|
|
7036
|
-
if (
|
|
7037
|
-
const
|
|
7338
|
+
calculateLatestUpdateTrigger(community);
|
|
7339
|
+
if (shouldStopPublishLoop()) return;
|
|
7340
|
+
const recordAlreadyRequested = !lastSyncFailed && community._communityUpdateTrigger;
|
|
7341
|
+
const minPauseMs = Math.min(MIN_MS_BETWEEN_PUBLISH_CYCLES, syncIntervalMs);
|
|
7342
|
+
const idleSleepMs = lastSyncFailed ? syncIntervalMs : Math.min(syncIntervalMs, Math.max(minPauseMs, msUntilLastPublishIsTooOld(community)));
|
|
7343
|
+
const sleepingSince = Date.now();
|
|
7038
7344
|
await new Promise((resolve) => {
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
if (
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7345
|
+
let timer;
|
|
7346
|
+
const endSleep = () => {
|
|
7347
|
+
clearTimeout(timer);
|
|
7348
|
+
if (community._wakePublishLoop === wake) community._wakePublishLoop = void 0;
|
|
7349
|
+
resolve();
|
|
7350
|
+
};
|
|
7351
|
+
const wake = () => {
|
|
7352
|
+
const pauseLeftMs = minPauseMs - (Date.now() - sleepingSince);
|
|
7353
|
+
if (pauseLeftMs <= 0 || shouldStopPublishLoop()) return endSleep();
|
|
7354
|
+
clearTimeout(timer);
|
|
7355
|
+
timer = setTimeout(endSleep, pauseLeftMs);
|
|
7356
|
+
};
|
|
7357
|
+
timer = setTimeout(endSleep, recordAlreadyRequested ? minPauseMs : idleSleepMs);
|
|
7358
|
+
community._wakePublishLoop = wake;
|
|
7047
7359
|
});
|
|
7048
7360
|
};
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7361
|
+
const releaseEventLoopWatch = holdEventLoopWatch();
|
|
7362
|
+
try {
|
|
7363
|
+
await runCyclesUntilStopped();
|
|
7364
|
+
} finally {
|
|
7365
|
+
releaseEventLoopWatch();
|
|
7366
|
+
}
|
|
7367
|
+
log("Stopping the publishing loop of community", community.address);
|
|
7368
|
+
async function runCyclesUntilStopped() {
|
|
7369
|
+
while (!shouldStopPublishLoop()) {
|
|
7370
|
+
if (isCommunityStartTakenByAnotherInstance(community, log)) {
|
|
7371
|
+
const error = new PKCError("ERR_COMMUNITY_START_TAKEN_BY_ANOTHER_PKC_INSTANCE", {
|
|
7372
|
+
address: community.address,
|
|
7373
|
+
dataPath: community._pkc.dataPath
|
|
7374
|
+
});
|
|
7375
|
+
log.error(error);
|
|
7376
|
+
community._startTakenByAnotherInstance = true;
|
|
7377
|
+
try {
|
|
7378
|
+
community.emit("error", error);
|
|
7379
|
+
} catch (e) {
|
|
7380
|
+
log.error(`A listener of the error of community (${community.address}) threw, or there is none`, e);
|
|
7381
|
+
}
|
|
7382
|
+
community.stop().catch((e) => log.error(`Failed to stop community (${community.address}) after its start was taken`, e));
|
|
7383
|
+
break;
|
|
7384
|
+
}
|
|
7385
|
+
let lastSyncFailed = false;
|
|
7057
7386
|
try {
|
|
7058
|
-
community
|
|
7387
|
+
await syncIpnsWithDb(community);
|
|
7388
|
+
await reprovideOnAddressChangeIfDue(community).catch((e) => log.error("Failed to re-provide connection CIDs on address change", e));
|
|
7389
|
+
await reprovideAnchorRecordIfDue(community).catch((e) => log.error("Failed to re-provide the anchor record", e));
|
|
7059
7390
|
} catch (e) {
|
|
7060
|
-
|
|
7391
|
+
lastSyncFailed = true;
|
|
7392
|
+
if (community._stopHasBeenCalled) syncFailedSinceStop = true;
|
|
7393
|
+
community.emit("error", e);
|
|
7394
|
+
} finally {
|
|
7395
|
+
await waitUntilNextSync({ lastSyncFailed });
|
|
7061
7396
|
}
|
|
7062
|
-
community.stop().catch((e) => log.error(`Failed to stop community (${community.address}) after its start was taken`, e));
|
|
7063
|
-
break;
|
|
7064
|
-
}
|
|
7065
|
-
let lastSyncFailed = false;
|
|
7066
|
-
try {
|
|
7067
|
-
await syncIpnsWithDb(community);
|
|
7068
|
-
await reprovideOnAddressChangeIfDue(community).catch((e) => log.error("Failed to re-provide connection CIDs on address change", e));
|
|
7069
|
-
await reprovideAnchorRecordIfDue(community).catch((e) => log.error("Failed to re-provide the anchor record", e));
|
|
7070
|
-
} catch (e) {
|
|
7071
|
-
lastSyncFailed = true;
|
|
7072
|
-
if (community._stopHasBeenCalled) syncFailedSinceStop = true;
|
|
7073
|
-
community.emit("error", e);
|
|
7074
|
-
} finally {
|
|
7075
|
-
await waitUntilNextSync({ lastSyncFailed });
|
|
7076
7397
|
}
|
|
7077
7398
|
}
|
|
7078
|
-
log("Stopping the publishing loop of community", community.address);
|
|
7079
7399
|
}
|
|
7080
7400
|
function isCommunityStartTakenByAnotherInstance(community, log) {
|
|
7081
7401
|
try {
|
|
@@ -7361,6 +7681,7 @@ async function stop(community) {
|
|
|
7361
7681
|
await (community._startOrUpdateInFlight ?? community._stopInFlight ?? Promise.allSettled([...community._editStoresInFlight]));
|
|
7362
7682
|
community._stopHasBeenCalled = true;
|
|
7363
7683
|
}
|
|
7684
|
+
community._wakePublishLoop?.();
|
|
7364
7685
|
let settle;
|
|
7365
7686
|
const stopInFlight = new Promise((resolve) => settle = resolve);
|
|
7366
7687
|
community._stopInFlight = stopInFlight;
|
|
@@ -8126,6 +8447,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8126
8447
|
set _communityUpdateTrigger(value) {
|
|
8127
8448
|
if (value) this._updateTriggerGeneration++;
|
|
8128
8449
|
this._communityUpdateTriggerValue = value;
|
|
8450
|
+
if (value) this._wakePublishLoop?.();
|
|
8129
8451
|
}
|
|
8130
8452
|
constructor(pkc) {
|
|
8131
8453
|
super(pkc);
|
|
@@ -8144,9 +8466,13 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8144
8466
|
this._slowGetChallengeWarningMs = SLOW_GET_CHALLENGE_WARNING_MS;
|
|
8145
8467
|
this._cidsToUnPin = /* @__PURE__ */ new Set();
|
|
8146
8468
|
this._mfsPathsToRemove = /* @__PURE__ */ new Set();
|
|
8469
|
+
this._postUpdatesBucketCids = /* @__PURE__ */ new Map();
|
|
8470
|
+
this._postUpdatesBucketPendingCids = /* @__PURE__ */ new Map();
|
|
8471
|
+
this._postUpdatesBucketsWithUnconfirmedRemovals = /* @__PURE__ */ new Set();
|
|
8147
8472
|
this._mfsPathRemovalWatchers = /* @__PURE__ */ new Set();
|
|
8148
8473
|
this._communityUpdateTriggerValue = false;
|
|
8149
8474
|
this._updateTriggerGeneration = 0;
|
|
8475
|
+
this._wakePublishLoop = void 0;
|
|
8150
8476
|
this._combinedHashOfPendingCommentsCids = (0, import_sha256.sha256)("");
|
|
8151
8477
|
this._pageSorts = void 0;
|
|
8152
8478
|
this._pageSortFactories = void 0;
|