-
Notifications
You must be signed in to change notification settings - Fork 4
Use @fastify/fastify-postgres. CheckerNetwork/roadmap#220 #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
31a5f9b
6206573
51bfcad
3717210
973b0da
826d075
e89a63c
26d73c7
2608fdc
c0a95b2
6a76461
f6a0319
59448e4
9423683
97ac2bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -13,12 +13,12 @@ | |||||||
}, | ||||||||
"dependencies": { | ||||||||
"@filecoin-station/spark-evaluate": "^1.2.0", | ||||||||
"pg": "^8.13.3", | ||||||||
"pg": "^8.14.0", | ||||||||
"postgrator": "^8.0.0" | ||||||||
}, | ||||||||
"standard": { | ||||||||
"env": [ | ||||||||
"mocha" | ||||||||
] | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @Goddhi |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
juliangruber marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -6,4 +6,4 @@ import { | |||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please undo this change to keep the diff clean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, noted |
||||||||
const pgPools = await getPgPools() | ||||||||
await migrateStatsDB(pgPools.stats) | ||||||||
await migrateEvaluateDB(pgPools.evaluate) | ||||||||
await migrateEvaluateDB(pgPools.evaluate) | ||||||||
|
await migrateEvaluateDB(pgPools.evaluate) | |
await migrateEvaluateDB(pgPools.evaluate) | |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,23 +1,26 @@ | ||||||||||
import '../lib/instrument.js' | ||||||||||
import { createApp } from '../lib/app.js' | ||||||||||
import { getPgPools } from '@filecoin-station/spark-stats-db' | ||||||||||
|
||||||||||
const { | ||||||||||
PORT = '8080', | ||||||||||
HOST = '127.0.0.1', | ||||||||||
SPARK_API_BASE_URL = 'https://api.filspark.com/', | ||||||||||
REQUEST_LOGGING = 'true' | ||||||||||
REQUEST_LOGGING = 'true', | ||||||||||
DATABASE_URL, | ||||||||||
EVALUATE_DB_URL | ||||||||||
|
DATABASE_URL, | |
EVALUATE_DB_URL | |
DATABASE_URL = 'postgres://localhost:5432/spark_stats', | |
EVALUATE_DB_URL = 'postgres://localhost:5432/spark_evaluate' |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -14,39 +14,56 @@ import { filterPreHandlerHook, filterOnSendHook } from './request-helpers.js' | |||||||
|
||||||||
/** @typedef {import('./typings.js').RequestWithFilter} RequestWithFilter */ | ||||||||
|
||||||||
export const addPlatformRoutes = (app, pgPools) => { | ||||||||
/** | ||||||||
* Create an adapter to convert Fastify pg to the expected pgPools format | ||||||||
* @param {any} pg Fastify pg object | ||||||||
* @returns {object} pgPools compatible object | ||||||||
*/ | ||||||||
|
||||||||
function adaptPgPools(pg) { | ||||||||
return { | ||||||||
stats: pg.stats, | ||||||||
evaluate: pg.evaluate, | ||||||||
end: async () => {} // Empty implementation | ||||||||
}; | ||||||||
} | ||||||||
|
||||||||
|
||||||||
export const addPlatformRoutes = (app) => { | ||||||||
app.register(async app => { | ||||||||
app.addHook('preHandler', filterPreHandlerHook) | ||||||||
app.addHook('onSend', filterOnSendHook) | ||||||||
|
||||||||
app.get('/stations/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||||
reply.send(await fetchDailyStationCount(pgPools.evaluate, request.filter)) | ||||||||
reply.send(await fetchDailyStationCount(request.server.pg.evaluate, request.filter)) | ||||||||
}) | ||||||||
app.get('/stations/monthly', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||||
reply.send(await fetchMonthlyStationCount(pgPools.evaluate, request.filter)) | ||||||||
reply.send(await fetchMonthlyStationCount(request.server.pg.evaluate, request.filter)) | ||||||||
}) | ||||||||
app.get('/stations/desktop/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||||
reply.send(await fetchDailyDesktopUsers(pgPools.stats, request.filter)) | ||||||||
reply.send(await fetchDailyDesktopUsers(request.server.pg.stats, request.filter)) | ||||||||
}) | ||||||||
app.get('/measurements/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||||
reply.send(await fetchDailyStationMeasurementCounts(pgPools.evaluate, request.filter)) | ||||||||
reply.send(await fetchDailyStationMeasurementCounts(request.server.pg.evaluate, request.filter)) | ||||||||
}) | ||||||||
app.get('/participants/top-measurements', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||||
reply.send(await fetchParticipantsWithTopMeasurements(pgPools.evaluate, request.filter)) | ||||||||
reply.send(await fetchParticipantsWithTopMeasurements(request.server.pg.evaluate, request.filter)) | ||||||||
}) | ||||||||
app.get('/participants/top-earning', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||||
reply.send(await fetchTopEarningParticipants(pgPools.stats, request.filter)) | ||||||||
}) | ||||||||
const pgPools = adaptPgPools(request.server.pg); | ||||||||
reply.send(await fetchTopEarningParticipants(pgPools.stats, request.filter)) }) | ||||||||
|
const pgPools = adaptPgPools(request.server.pg); | |
reply.send(await fetchTopEarningParticipants(pgPools.stats, request.filter)) }) | |
reply.send(await fetchTopEarningParticipants(request.server.pg.stats, request.filter)) }) |
What do we need the adaptPgPools
function for here?
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,57 +23,89 @@ import { | |
/** @typedef {import('./typings.js').RequestWithFilterAndMinerId} RequestWithFilterAndMinerId */ | ||
/** @typedef {import('./typings.js').RequestWithFilterAndClientId} RequestWithFilterAndClientId */ | ||
|
||
export const addRoutes = (app, pgPools, SPARK_API_BASE_URL) => { | ||
/** | ||
* Create an adapter to convert Fastify pg to the expected pgPools format | ||
* @param {any} pg Fastify pg object | ||
* @returns {object} pgPools compatible object | ||
*/ | ||
|
||
function adaptPgPools(pg) { | ||
return { | ||
stats: pg.stats, | ||
evaluate: pg.evaluate, | ||
end: async () => {} | ||
}; | ||
} | ||
|
||
export const addRoutes = (app, SPARK_API_BASE_URL) => { | ||
app.register(async app => { | ||
app.addHook('preHandler', filterPreHandlerHook) | ||
app.addHook('onSend', filterOnSendHook) | ||
|
||
app.get('/deals/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
|
||
reply.send(await fetchDailyDealStats(pgPools, request.filter)) | ||
}) | ||
|
||
|
||
app.get('/deals/summary', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg) | ||
reply.send(await fetchDealSummary(pgPools, request.filter)) | ||
}) | ||
app.get('/retrieval-success-rate', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchRetrievalSuccessRate(pgPools, request.filter)) | ||
}) | ||
app.get('/participants/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg) | ||
reply.send(await fetchDailyParticipants(pgPools, request.filter)) | ||
}) | ||
app.get('/participants/monthly', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchMonthlyParticipants(pgPools, request.filter)) | ||
}) | ||
app.get('/participants/change-rates', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchParticipantChangeRates(pgPools, request.filter)) | ||
}) | ||
app.get('/participant/:address/scheduled-rewards', async (/** @type {RequestWithFilterAndAddress} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchParticipantScheduledRewards(pgPools, request.filter, request.params.address)) | ||
}) | ||
app.get('/participant/:address/reward-transfers', async (/** @type {RequestWithFilterAndAddress} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchParticipantRewardTransfers(pgPools, request.filter, request.params.address)) | ||
}) | ||
app.get('/miners/retrieval-success-rate/summary', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchMinersRSRSummary(pgPools, request.filter)) | ||
}) | ||
app.get('/miners/retrieval-timings/summary', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchMinersTimingsSummary(pgPools, request.filter)) | ||
}) | ||
app.get('/retrieval-result-codes/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchDailyRetrievalResultCodes(pgPools, request.filter)) | ||
}) | ||
app.get('/retrieval-timings/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchDailyRetrievalTimings(pgPools, request.filter)) | ||
}) | ||
app.get('/miner/:minerId/retrieval-timings/summary', async (/** @type {RequestWithFilterAndMinerId} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchDailyMinerRetrievalTimings(pgPools, request.filter, request.params.minerId)) | ||
}) | ||
app.get('/miner/:minerId/retrieval-success-rate/summary', async (/** @type {RequestWithFilterAndMinerId} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchDailyMinerRSRSummary(pgPools, request.filter, request.params.minerId)) | ||
}) | ||
app.get('/clients/retrieval-success-rate/summary', async (/** @type {RequestWithFilter} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchClientsRSRSummary(pgPools, request.filter)) | ||
}) | ||
app.get('/client/:clientId/retrieval-success-rate/summary', async (/** @type {RequestWithFilterAndClientId} */ request, reply) => { | ||
const pgPools = adaptPgPools(request.server.pg); | ||
reply.send(await fetchDailyClientRSRSummary(pgPools, request.filter, request.params.clientId)) | ||
}) | ||
}) | ||
|
Uh oh!
There was an error while loading. Please reload this page.