[indexing] save missing fee_percentiles and median_fee_amt when indexing on the fly
				
					
				
			This commit is contained in:
		
							parent
							
								
									b23f14b798
								
							
						
					
					
						commit
						6016db2533
					
				@ -857,6 +857,7 @@ class Blocks {
 | 
			
		||||
        }
 | 
			
		||||
        if (cleanBlock.fee_amt_percentiles !== null) {
 | 
			
		||||
          cleanBlock.median_fee_amt = cleanBlock.fee_amt_percentiles[3];
 | 
			
		||||
          await blocksRepository.$updateFeeAmounts(cleanBlock.hash, cleanBlock.fee_amt_percentiles, cleanBlock.median_fee_amt);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -213,6 +213,32 @@ class BlocksRepository {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Update missing fee amounts fields
 | 
			
		||||
   *
 | 
			
		||||
   * @param blockHash 
 | 
			
		||||
   * @param feeAmtPercentiles 
 | 
			
		||||
   * @param medianFeeAmt 
 | 
			
		||||
   */
 | 
			
		||||
  public async $updateFeeAmounts(blockHash: string, feeAmtPercentiles, medianFeeAmt) : Promise<void> {
 | 
			
		||||
    try {
 | 
			
		||||
      const query = `
 | 
			
		||||
        UPDATE blocks
 | 
			
		||||
        SET fee_percentiles = ?, median_fee_amt = ?
 | 
			
		||||
        WHERE hash = ?
 | 
			
		||||
      `;
 | 
			
		||||
      const params: any[] = [
 | 
			
		||||
        JSON.stringify(feeAmtPercentiles),
 | 
			
		||||
        medianFeeAmt,
 | 
			
		||||
        blockHash
 | 
			
		||||
      ];
 | 
			
		||||
      await DB.query(query, params);
 | 
			
		||||
    } catch (e: any) {
 | 
			
		||||
      logger.err(`Cannot update fee amounts for block ${blockHash}. Reason: ' + ${e instanceof Error ? e.message : e}`);
 | 
			
		||||
      throw e;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get all block height that have not been indexed between [startHeight, endHeight]
 | 
			
		||||
   */
 | 
			
		||||
@ -1027,6 +1053,7 @@ class BlocksRepository {
 | 
			
		||||
      }
 | 
			
		||||
      if (extras.feePercentiles !== null) {
 | 
			
		||||
        extras.medianFeeAmt = extras.feePercentiles[3];
 | 
			
		||||
        await this.$updateFeeAmounts(dbBlk.id, extras.feePercentiles, extras.medianFeeAmt);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user