Skip to content

Conversation

@paullinator
Copy link
Member

@paullinator paullinator commented Dec 22, 2022


import { setAsync, slackMessage } from './utils/dbUtils'
import { logger, snooze } from './utils/utils'

const client = createClient()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to create another client

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. done

const LOOP_DELAY = 45000

export const coinrankEngine = async (): Promise<void> => {
await console.log('hello')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove testing remnant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

try {
const lastUpdate = new Date().toISOString()
const { uri } = config.providers.coingecko
let markets: any = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be typed as CoinrankMarkets instead of any

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Done

const marketsPage = asCoingeckoMarkets(reply)
markets = [...markets, ...marketsPage]
} catch (e) {
console.log('ugh')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's let the cleaner throw so we don't update the redis list with incomplete data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. done


// Update redis cache
const redisData: CoinrankRedis = {
markets: data,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only saves the the sliced data for the requested fiat. Convert everything in the USD list to the selected currency before saving it and returning to the user

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. All USD market are queried by the engine. The API endpoint only writes non-USD markets after doing the conversion. The converted value is returned to the user and saved in redis.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data saved to redis is only a subset of the USD data (sliced at 378 and saved in line 392) and once it is saved subsequent requests for the same fiat code will no longer be null at line 361 which skips any conversion functionality.

Instead, take markets in line 377 and convert all of them to the requested fiat -> save to redis -> slice and return to user

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood. makes sense.

.send(`Invalid length param: ${length}. Must be between 1-100`)
return
}
const fiatSuffix = fiatCode.split(':')[1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, just use the fiatCode as is for the key. And replace any hardcoded USD/iso:USD value with the default fiat from the config

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. note there are other hardcoded iso:USD occurences in the file


// Update redis cache
const redisData: CoinrankRedis = {
markets: data,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data saved to redis is only a subset of the USD data (sliced at 378 and saved in line 392) and once it is saved subsequent requests for the same fiat code will no longer be null at line 361 which skips any conversion functionality.

Instead, take markets in line 377 and convert all of them to the requested fiat -> save to redis -> slice and return to user

await setupDatabase(config.couchUri, ratesDbSetup)
ratesEngine().catch(e => logger('ratesEnginee failure', e))
uidEngine().catch(e => logger('uidEnginee failure', e))
// ratesEngine().catch(e => logger('ratesEnginee failure', e))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turd here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn. the whole file change is a turd. how'd that sneak in there. will remove

ratesEngine().catch(e => logger('ratesEnginee failure', e))
uidEngine().catch(e => logger('uidEnginee failure', e))
// ratesEngine().catch(e => logger('ratesEnginee failure', e))
// uidEngine().catch(e => logger('uidEnginee failure', e))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another turd

@paullinator paullinator merged commit 8a859da into master Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants