Ignore prices without USD exchange rate
This commit is contained in:
		
							parent
							
								
									1037fbe52b
								
							
						
					
					
						commit
						682682c74a
					
				@ -4,6 +4,12 @@ import { Prices } from '../tasks/price-updater';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class PricesRepository {
 | 
					class PricesRepository {
 | 
				
			||||||
  public async $savePrices(time: number, prices: Prices): Promise<void> {
 | 
					  public async $savePrices(time: number, prices: Prices): Promise<void> {
 | 
				
			||||||
 | 
					    if (prices.USD === -1) {
 | 
				
			||||||
 | 
					      // Some historical price entries have not USD prices, so we just ignore them to avoid future UX issues
 | 
				
			||||||
 | 
					      // As of today there are only 4 (on 2013-09-05, 2013-09-19, 2013-09-12 and 2013-09-26) so that's fine
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      await DB.query(`
 | 
					      await DB.query(`
 | 
				
			||||||
        INSERT INTO prices(time,             USD, EUR, GBP, CAD, CHF, AUD, JPY)
 | 
					        INSERT INTO prices(time,             USD, EUR, GBP, CAD, CHF, AUD, JPY)
 | 
				
			||||||
@ -17,17 +23,17 @@ class PricesRepository {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public async $getOldestPriceTime(): Promise<number> {
 | 
					  public async $getOldestPriceTime(): Promise<number> {
 | 
				
			||||||
    const [oldestRow] = await DB.query(`SELECT UNIX_TIMESTAMP(time) as time from prices ORDER BY time LIMIT 1`);
 | 
					    const [oldestRow] = await DB.query(`SELECT UNIX_TIMESTAMP(time) as time from prices WHERE USD != -1 ORDER BY time LIMIT 1`);
 | 
				
			||||||
    return oldestRow[0] ? oldestRow[0].time : 0;
 | 
					    return oldestRow[0] ? oldestRow[0].time : 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public async $getLatestPriceTime(): Promise<number> {
 | 
					  public async $getLatestPriceTime(): Promise<number> {
 | 
				
			||||||
    const [oldestRow] = await DB.query(`SELECT UNIX_TIMESTAMP(time) as time from prices ORDER BY time DESC LIMIT 1`);
 | 
					    const [oldestRow] = await DB.query(`SELECT UNIX_TIMESTAMP(time) as time from prices WHERE USD != -1 ORDER BY time DESC LIMIT 1`);
 | 
				
			||||||
    return oldestRow[0] ? oldestRow[0].time : 0;
 | 
					    return oldestRow[0] ? oldestRow[0].time : 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public async $getPricesTimes(): Promise<number[]> {
 | 
					  public async $getPricesTimes(): Promise<number[]> {
 | 
				
			||||||
    const [times]: any[] = await DB.query(`SELECT UNIX_TIMESTAMP(time) as time from prices`);
 | 
					    const [times]: any[] = await DB.query(`SELECT UNIX_TIMESTAMP(time) as time from prices WHERE USD != -1`);
 | 
				
			||||||
    return times.map(time => time.time);
 | 
					    return times.map(time => time.time);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user