-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent race conditions and add logs (#889)
- Loading branch information
Showing
8 changed files
with
69 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { IBaseComponent } from '@well-known-components/interfaces' | ||
import future from 'fp-future' | ||
import { streamAllEntityIds } from '../logic/database-queries/deployments-queries' | ||
import { AppComponents } from '../types' | ||
import { createBloomFilterComponent } from './bloomFilter' | ||
|
||
export type DeploymentListComponent = { | ||
add(entityId: string): void | ||
check(entityId: string): Promise<boolean> | ||
} | ||
|
||
export function createDeploymentListComponent( | ||
components: Pick<AppComponents, 'database' | 'logs'> | ||
): DeploymentListComponent & IBaseComponent { | ||
const bloom = createBloomFilterComponent({ sizeInBytes: 512 }) | ||
|
||
const initialized = future<void>() | ||
|
||
const logs = components.logs.getLogger('DeploymentListComponent') | ||
|
||
async function addFromDb() { | ||
const start = Date.now() | ||
logs.info(`Creating bloom filter`, {}) | ||
let elements = 0 | ||
for await (const row of streamAllEntityIds(components)) { | ||
elements++ | ||
bloom.add(row.entityId) | ||
} | ||
logs.info(`Bloom filter recreated.`, { timeMs: Date.now() - start, elements }) | ||
} | ||
|
||
return { | ||
add(entityId: string) { | ||
bloom.add(entityId) | ||
}, | ||
async check(entityId: string) { | ||
await initialized | ||
return bloom.check(entityId) | ||
}, | ||
async start() { | ||
await addFromDb() | ||
initialized.resolve() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters