Skip to content

Commit

Permalink
fix(locksmith): changing indices on process hook items (#15390)
Browse files Browse the repository at this point in the history
changing indices on process hook items
  • Loading branch information
julien51 authored Jan 22, 2025
1 parent 4ed31df commit fb11d6b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
8 changes: 8 additions & 0 deletions locksmith/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ You can start a worker with `yarn worker:start`.

You can also run scripts with `yarn run runner ./src/scripts/script.ts` (check the sample file for an example).

### Debugging

It is possible to create files and run them locally

```sh
yarn run runner src/debug.ts
```

## Attributions

This product uses GeoLite2 data created by MaxMind, available from [https://www.maxmind.com](https://www.maxmind.com).
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

const table = 'EventData'

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addIndex('ProcessedHookItems', {
fields: ['objectId', 'network'],
unique: true,
})
await queryInterface.removeIndex(
'ProcessedHookItems',
'processed_hook_items_object_id'
)
},

down: async (queryInterface, Sequelize) => {
await queryInterface.addIndex('ProcessedHookItems', {
fields: ['objectId'],
unique: true,
})

await queryInterface.removeIndex(
'ProcessedHookItems',
'processed_hook_items_object_id_network'
)
},
}
7 changes: 2 additions & 5 deletions locksmith/src/worker/jobs/locks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async function handleNetworkLocks(hooks: Hook[], network: number) {
const newLocks = await fetchUnprocessedLocks(network, page)

if (!newLocks.length) {
logger.info(`No new locks found for network ${network}`)
logger.info(`No more new locks found for network ${network}`)
break
}

Expand All @@ -256,16 +256,13 @@ async function handleNetworkLocks(hooks: Hook[], network: number) {
*/
export async function notifyOfLocks(hooks: Hook[]) {
const subscribedHooks = filterHooksByTopic(hooks, TOPIC_LOCKS)
const networkTasks: Promise<void>[] = []

for (const network of Object.values(networks)) {
if (network.id === 31337) continue // Skip local network

const networkHooks = subscribedHooks.filter(
(hook) => hook.network === network.id
)
networkTasks.push(handleNetworkLocks(networkHooks, network.id))
await handleNetworkLocks(networkHooks, network.id)
}

await Promise.allSettled(networkTasks)
}

0 comments on commit fb11d6b

Please sign in to comment.