-
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 all 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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -21,4 +21,4 @@ | |||||||
"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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
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 = 'postgres://localhost:5432/spark_stats', | ||
EVALUATE_DB_URL = 'postgres://localhost:5432/spark_evaluate' | ||
} = process.env | ||
|
||
const pgPools = await getPgPools() | ||
|
||
const app = await createApp({ | ||
SPARK_API_BASE_URL, | ||
pgPools, | ||
DATABASE_URL, | ||
EVALUATE_DB_URL, | ||
logger: { | ||
level: ['1', 'true'].includes(REQUEST_LOGGING) ? 'info' : 'error' | ||
} | ||
}) | ||
|
||
console.log('Starting the http server on host %j port %s', HOST, PORT) | ||
const baseUrl = app.listen({ port: Number(PORT), host: HOST }) | ||
console.log(baseUrl) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,39 +14,40 @@ import { filterPreHandlerHook, filterOnSendHook } from './request-helpers.js' | |||||
|
||||||
/** @typedef {import('./typings.js').RequestWithFilter} RequestWithFilter */ | ||||||
|
||||||
export const addPlatformRoutes = (app, pgPools) => { | ||||||
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, 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, request.filter)) | ||||||
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
We could also pass correct instance of the database instead of passing the 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. This throws an error reason why went with only the pg object, besides the fetcher functions expects full pg object and uses pg.stats or pg.evaluate interally. 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. What error does it throw? 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 |
||||||
}) | ||||||
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, 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, 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, request.filter)) | ||||||
}) | ||||||
app.get('/participants/top-earning', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||
reply.send(await fetchTopEarningParticipants(pgPools.stats, request.filter)) | ||||||
reply.send(await fetchTopEarningParticipants(request.server.pg, request.filter)) | ||||||
}) | ||||||
|
||||||
app.get('/participants/accumulative/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||
reply.send(await fetchAccumulativeDailyParticipantCount(pgPools.evaluate, request.filter)) | ||||||
reply.send(await fetchAccumulativeDailyParticipantCount(request.server.pg, request.filter)) | ||||||
}) | ||||||
app.get('/transfers/daily', async (/** @type {RequestWithFilter} */ request, reply) => { | ||||||
reply.send(await fetchDailyRewardTransfers(pgPools.stats, request.filter)) | ||||||
reply.send(await fetchDailyRewardTransfers(request.server.pg, request.filter)) | ||||||
}) | ||||||
}) | ||||||
|
||||||
app.get('/participants/summary', async (request, reply) => { | ||||||
reply.header('cache-control', `public, max-age=${24 * 3600 /* one day */}`) | ||||||
reply.send(await fetchParticipantsSummary(pgPools.evaluate)) | ||||||
reply.send(await fetchParticipantsSummary(request.server.pg)) | ||||||
bajtos marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}) | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.