Skip to content

Commit

Permalink
Merge pull request #682 from near/revert-681-fix/error-reconnect
Browse files Browse the repository at this point in the history
Revert "feat: end and reconnect pool after error"
  • Loading branch information
andy-haynes authored Mar 13, 2024
2 parents 359c4c4 + a57a3a4 commit 51ba1a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 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
2 changes: 1 addition & 1 deletion test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function createAllRecoveryMethods({ accountId }) {
);
}

describe('app routes', function () {
describe.skip('app routes', function () {
this.timeout(20000);

let app, request, testAccountHelper;
Expand Down

0 comments on commit 51ba1a0

Please sign in to comment.