Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pdp2121 committed Dec 19, 2024
1 parent 0b1b783 commit da4e553
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/shared/database/amendments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ async function fetchNetworkAmendments(
}

/**
* Fetch an amendment info from a network.
* Find an amendment info from a network and add to current map.
*
* @param amendment_id - The id of the amendment to fetch.
* @param url - The Faucet URL of the network.
*
* @returns True if the amendment is found, false otherwise.
*/
async function fetchSingleAmendment(
async function findSingleAmendment(
amendment_id: string,
url: string,
): Promise<boolean> {
Expand Down Expand Up @@ -134,15 +134,17 @@ async function fetchSingleAmendment(
}

/**
* Search for a single amendment across networks.
* Fetch for a single amendment across networks. Returns when the first one is found.
*
* @param amendment_id - The id of the amendment to search.
*
* @returns Void.
*/
async function findSingleAmendment(amendment_id: string): Promise<void> {
async function fetchSingleAmendmentFromNetworks(
amendment_id: string,
): Promise<void> {
for (const url of Object.values(NETWORKS_HOSTS)) {
const found = await fetchSingleAmendment(amendment_id, url)
const found = await findSingleAmendment(amendment_id, url)
if (found) {
break
}
Expand All @@ -156,20 +158,23 @@ async function findSingleAmendment(amendment_id: string): Promise<void> {
*/
async function fetchMissingAmendments(): Promise<void> {
const voting = new Set<string>()
await query('ballot')
const votingDb = await query('ballot')
.select('amendments')
.then((res) => {
for (const obj of res) {
const amendmentsString = obj.amendments
const amendments = amendmentsString ? amendmentsString.split(',') : []
for (const amendment of amendments) {
voting.add(amendment)
}
}
})
.then(async (res) =>
res.map((vote: { amendments: string | null }) => vote.amendments),
)
for (const amendmentsDb of votingDb) {
if (!amendmentsDb) {
continue
}
const amendments = amendmentsDb.split(',')
for (const amendment of amendments) {
voting.add(amendment)
}
}
for (const amendment of voting) {
if (!amendmentIDs.has(amendment)) {
await findSingleAmendment(amendment)
await fetchSingleAmendmentFromNetworks(amendment)
}
}
}
Expand Down

0 comments on commit da4e553

Please sign in to comment.