From 2b1cf691206e8c5a03a2a4c3ab94ff0fca2736e5 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sat, 30 Jun 2018 14:28:50 +0200
Subject: [PATCH] [fix] sync: filter on *wanted* blocks

---
 app/modules/crawler/lib/sync/ChunkGetter.ts | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/app/modules/crawler/lib/sync/ChunkGetter.ts b/app/modules/crawler/lib/sync/ChunkGetter.ts
index 2c0f146b2..54b312eec 100644
--- a/app/modules/crawler/lib/sync/ChunkGetter.ts
+++ b/app/modules/crawler/lib/sync/ChunkGetter.ts
@@ -93,7 +93,7 @@ export class ChunkGetter {
     }
 
     // Download loop
-    (async () => {
+    return (async () => {
       let downloadFinished = false
       while(!downloadFinished) {
 
@@ -233,7 +233,12 @@ export class ChunkGetter {
   }
 
   async getChunk(i: number): Promise<PromiseOfBlocksReading> {
-    return this.resultsData[i] || Promise.resolve(async (): Promise<BlockDTO[]> => [])
+    const reading = this.resultsData[i] || Promise.resolve(async (): Promise<BlockDTO[]> => [])
+    // We don't want blocks above `to`
+    return async () => {
+      const blocks = await (await reading)()
+      return blocks.filter(b => b.number <= this.to)
+    }
   }
 }
 
-- 
GitLab