Skip to content

Commit

Permalink
Revert "feat: end and reconnect pool after error"
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-haynes authored Mar 13, 2024
1 parent 359c4c4 commit 8b3975f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/middleware/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,18 @@ const {

const replicaConnections = JSON.parse(INDEXER_DB_REPLICAS);
const indexerConnection = replicaConnections[(new Date()).valueOf() % replicaConnections.length];
let pool = new Pool({ connectionString: indexerConnection, maxUses: 1000 });
const pool = new Pool({ connectionString: indexerConnection, maxUses: 1000 });

pool.on('error', (err) => {
console.error('Postgres pool error: ', err);
pool.end()
.then(() => {
pool = new Pool({ connectionString: indexerConnection, maxUses: 1000 });
})
.catch(() => {
console.error('failed to drain PG connection pool');
});
});

const poolMatch = NEAR_WALLET_ENV.startsWith('mainnet')
? JSON.stringify(['%.poolv1.near', '%.pool.near']).replace(/"/g, '\'')
: JSON.stringify(['%.pool.%.m0', '%.factory01.littlefarm.testnet', '%.factory.colorpalette.testnet']).replace(/"/g, '\'');

const findLastBlockByTimestamp = async () => {
const { rows: [lastBlock] } = await pool.query('select block_timestamp FROM blocks ORDER BY block_timestamp DESC LIMIT 1');
const { rows: [ lastBlock ] } = await pool.query('select block_timestamp FROM blocks ORDER BY block_timestamp DESC LIMIT 1');
return lastBlock;
};

Expand Down Expand Up @@ -134,7 +127,7 @@ const findReceivers = async (ctx) => {
};

const likelyTokensFromBlock = async ({ fromBlockTimestamp, accountId }) => {
const { block_timestamp: lastBlockTimestamp } = await findLastBlockByTimestamp();
const { block_timestamp: lastBlockTimestamp } = await findLastBlockByTimestamp();

const received = `
select distinct receipt_receiver_account_id as receiver_account_id
Expand Down Expand Up @@ -175,7 +168,7 @@ const likelyTokensFromBlock = async ({ fromBlockTimestamp, accountId }) => {
};

const likelyNFTsFromBlock = async ({ fromBlockTimestamp, accountId }) => {
const { block_timestamp: lastBlockTimestamp } = await findLastBlockByTimestamp();
const { block_timestamp: lastBlockTimestamp } = await findLastBlockByTimestamp();

const ownershipChangeFunctionCalls = `
select distinct receipt_receiver_account_id as receiver_account_id
Expand Down Expand Up @@ -215,7 +208,7 @@ const findLikelyTokensFromBlock = async (ctx) => {
fromBlockTimestamp,
accountId
});

ctx.body = {
version: '1.0.0',
lastBlockTimestamp,
Expand Down

0 comments on commit 8b3975f

Please sign in to comment.