Add --reindex command line parameter to force full re-indexing
				
					
				
			This commit is contained in:
		
							parent
							
								
									e5907159b8
								
							
						
					
					
						commit
						bb1c5d0b31
					
				@ -419,6 +419,29 @@ class DatabaseMigration {
 | 
			
		||||
      FOREIGN KEY (pool_id) REFERENCES pools (id)
 | 
			
		||||
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async $truncateIndexedData(tables: string[]) {
 | 
			
		||||
    const allowedTables = ['blocks', 'hashrates'];
 | 
			
		||||
 | 
			
		||||
    const connection = await DB.pool.getConnection();
 | 
			
		||||
    try {
 | 
			
		||||
      for (const table of tables) {
 | 
			
		||||
        if (!allowedTables.includes(table)) {
 | 
			
		||||
          logger.info(`Table ${table} cannot to be re-indexed (not allowed)`);
 | 
			
		||||
          continue;
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        await this.$executeQuery(connection, `TRUNCATE ${table}`, true);
 | 
			
		||||
        if (table === 'hashrates') {
 | 
			
		||||
          await this.$executeQuery(connection, 'UPDATE state set number = 0 where name = "last_hashrates_indexing"', true);
 | 
			
		||||
        }
 | 
			
		||||
        logger.info(`Table ${table} has been truncated`);
 | 
			
		||||
      }
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      logger.warn(`Unable to erase indexed data`);
 | 
			
		||||
    }
 | 
			
		||||
    connection.release();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default new DatabaseMigration();
 | 
			
		||||
 | 
			
		||||
@ -89,6 +89,12 @@ class Server {
 | 
			
		||||
    if (config.DATABASE.ENABLED) {
 | 
			
		||||
      await checkDbConnection();
 | 
			
		||||
      try {
 | 
			
		||||
        if (process.env.npm_config_reindex != undefined) { // Re-index requests
 | 
			
		||||
          const tables = process.env.npm_config_reindex.split(',');
 | 
			
		||||
          logger.warn(`Indexed data for "${process.env.npm_config_reindex}" tables will be erased in 5 seconds from now (using '--reindex') ...`);
 | 
			
		||||
          await Common.sleep(5000);
 | 
			
		||||
          await databaseMigration.$truncateIndexedData(tables);
 | 
			
		||||
        }
 | 
			
		||||
        await databaseMigration.$initializeOrMigrateDatabase();
 | 
			
		||||
        await poolsParser.migratePoolsJson();
 | 
			
		||||
      } catch (e) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user