Browse Source

storage-node: only sync Accepted content

Mokhtar Naamani 4 years ago
parent
commit
ee4eb9ede7

+ 2 - 2
storage-node/packages/colossus/lib/sync.js

@@ -25,7 +25,7 @@ const { ContentId } = require('@joystream/types/storage')
 const MAX_CONCURRENT_SYNC_ITEMS = 20
 
 async function syncContent({ api, storage, contentBeingSynced, contentCompleteSynced }) {
-  const knownEncodedContentIds = (await api.assets.getKnownContentIds()).map((id) => id.encode())
+  const knownEncodedContentIds = (await api.assets.getAcceptedContentIds()).map((id) => id.encode())
 
   // Select ids which we have not yet fully synced
   const needsSync = knownEncodedContentIds
@@ -155,7 +155,7 @@ async function syncPeriodic({ api, flags, storage, contentBeingSynced, contentCo
 
     await syncContent({ api, storage, contentBeingSynced, contentCompleteSynced })
 
-    // Only update on chain state if not in anonymous mode
+    // Only update on-chain state if not in anonymous mode
     if (!flags.anonymous) {
       const relationshipIds = await createNewRelationships({ api, contentCompleteSynced })
       await setRelationshipsReady({ api, relationshipIds })

+ 16 - 0
storage-node/packages/runtime-api/assets.js

@@ -163,6 +163,22 @@ class AssetsApi {
     const keys = await this.base.api.query.dataDirectory.dataByContentId.keys()
     return keys.map(({ args: [contentId] }) => contentId)
   }
+
+  /*
+   * Returns array of all content ids in storage where liaison judgement was Accepted
+   */
+  async getAcceptedContentIds() {
+    const entries = await this.base.api.query.dataDirectory.dataByContentId.entries()
+    return entries
+      .filter(([, dataObject]) => dataObject.liaison_judgement.type === 'Accepted')
+      .map(
+        ([
+          {
+            args: [contentId],
+          },
+        ]) => contentId
+      )
+  }
 }
 
 module.exports = {