Skip to content
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

Release #134

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/audit_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
uses: actions/checkout@v4

- name: Audit dependencies
run: audit-ci --critical --report-type full
Expand All @@ -36,14 +36,14 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
uses: actions/checkout@v4

- name: Set pnpm cache directory
run: pnpm config set store-dir .pnpm-store
continue-on-error: true

- name: Setup cache
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # pin@v2
uses: actions/checkout@v4
with:
path: |
.pnpm-store
Expand Down
26 changes: 20 additions & 6 deletions src/routes/v3/base/lt-trades.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const express = require('express');
const router = express.Router();
const { log, postgresClient, getCache, setCache } = require('../../../utils');
const cacheKey = 'base-lt-trades';
const cacheKeyPrefix = 'base-lt-trades';
fetchDataFromPostgres();
const cacheTime =
((process.env.CACHE_TIME =
Expand Down Expand Up @@ -97,31 +97,45 @@
router.get('/', async (req, res, next) => {
try {
log.debug('Checking cache..');
const { account } = req.query;
const cacheKey = account ? `${cacheKeyPrefix}-${account}` : cacheKeyPrefix;
const cachedResponse = await getCache(cacheKey);

if (cachedResponse) {
log.debug('Cache found');
res.json(cachedResponse);
} else {
log.debug('Cache not found, executing..');
const responseData = await fetchDataFromPostgres();
const responseData = await fetchDataFromPostgres(account);
res.json(responseData);
}
} catch (error) {
log.error(`[ltBaseTrade] Error: ${error.message}`);

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
next(error);
}
});
module.exports = router;
async function fetchDataFromPostgres() {
async function fetchDataFromPostgres(account) {
log.debug('[ltBaseTrade] Fetching data from postgres..');
const queryResult = await postgresClient.query(
`select *

const query = account
? `select *
from prod_base_mainnet.lt_trades_base_mainnet
where account = $1
order by block_number desc
limit 100;`
: `select *
from prod_base_mainnet.lt_trades_base_mainnet
order by block_number desc
limit 100;`,
limit 100;`;

const queryResult = await postgresClient.query(
query,
account ? [account] : [],
);
const responseData = queryResult.rows;
log.debug('[ltBaseTrade] Setting cache..');
const cacheKey = account ? `${cacheKeyPrefix}-${account}` : cacheKeyPrefix;
await setCache(cacheKey, responseData, 60);
return responseData;
}
26 changes: 20 additions & 6 deletions src/routes/v3/optimism/lt-trades.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const express = require('express');
const router = express.Router();
const { log, postgresClient, getCache, setCache } = require('../../../utils');
const cacheKey = 'optimism-lt-trades';
const cacheKeyPrefix = 'optimism-lt-trades';
fetchDataFromPostgres();
const cacheTime =
((process.env.CACHE_TIME =
Expand Down Expand Up @@ -97,31 +97,45 @@
router.get('/', async (req, res, next) => {
try {
log.debug('Checking cache..');
const { account } = req.query;
const cacheKey = account ? `${cacheKeyPrefix}-${account}` : cacheKeyPrefix;
const cachedResponse = await getCache(cacheKey);

if (cachedResponse) {
log.debug('Cache found');
res.json(cachedResponse);
} else {
log.debug('Cache not found, executing..');
const responseData = await fetchDataFromPostgres();
const responseData = await fetchDataFromPostgres(account);
res.json(responseData);
}
} catch (error) {
log.error(`[ltOptimismTrade] Error: ${error.message}`);

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
next(error);
}
});
module.exports = router;
async function fetchDataFromPostgres() {
async function fetchDataFromPostgres(account) {
log.debug('[ltOptimismTrade] Fetching data from postgres..');
const queryResult = await postgresClient.query(
`select *

const query = account
? `select *
from prod_optimism_mainnet.lt_trades_optimism_mainnet
where account = $1
order by block_number desc
limit 100;`
: `select *
from prod_optimism_mainnet.lt_trades_optimism_mainnet
order by block_number desc
limit 100;`,
limit 100;`;

const queryResult = await postgresClient.query(
query,
account ? [account] : [],
);
const responseData = queryResult.rows;
log.debug('[ltOptimismTrade] Setting cache..');
const cacheKey = account ? `${cacheKeyPrefix}-${account}` : cacheKeyPrefix;
await setCache(cacheKey, responseData, 60);
return responseData;
}
Loading