From c9384483c55c565e0196f5fb02dcfa7a31f9150b Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sat, 17 Nov 2018 16:19:17 +0100
Subject: [PATCH] [fix] Sync fail with chained transactions

---
 app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts
index cb369b75a..fb9ba5120 100644
--- a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts
+++ b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts
@@ -365,14 +365,16 @@ export class GlobalIndexStream extends Duplex {
   }
 
   @MonitorExecutionTime()
-  private async blockFillTxSourcesConditions(local_sindex: any[] | SindexEntry[]) {
+  private async blockFillTxSourcesConditions(local_sindex: SindexEntry[]) {
     // Fills in correctly the SINDEX
     await Promise.all(Underscore.where(local_sindex, {op: 'UPDATE'}).map(async entry => {
       if (!entry.conditions) {
         if (entry.srcType === 'D') {
           entry.conditions = 'SIG(' + entry.identifier + ')'
         } else {
-          const src = (await this.dal.getSource(entry.identifier, entry.pos, false)) as FullSindexEntry
+          // First: have a look locally, but only chained transactions would have `localSrc` matching (giving conditions)
+          const localSrc = local_sindex.filter(s => s.identifier === entry.identifier && s.pos === entry.pos && s.conditions)[0]
+          const src = localSrc || (await this.dal.getSource(entry.identifier, entry.pos, false)) as FullSindexEntry
           entry.conditions = src.conditions
         }
       }
-- 
GitLab