-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update SRP sync to use ESI rather than ZKillboard
Implements a new version of syncKillmails that employs flows and updated market data sources. Attempts to recreate the metadata provided by zkill as much as possible, namely the "npc" and fitted/totalValue fields, but we can't recreate everything, sadly (especially the "solo" field). Additionally, the ESI endpoint only returns killmails for which a corp member provided the killing blow, so we will lose access to some kills that were previously provided by ZKill. however, the SRP system really only needs access to the losses; the kills exist solely to provide context for SRP triagers. A couple of additional pieces of work need to occur after this change. First, we need to rename all usages of ZKillmail to something more generic like AnnotatedKillmail. Second, many of our losses do not appear in ZKill anymore, so we need to provide a detail view page for every killmail we store.
- Loading branch information
Showing
17 changed files
with
488 additions
and
457 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Adds ON CASCADE DELETE to the killmail_id part of killmailBattle | ||
*/ | ||
|
||
exports.up = async function (trx) { | ||
await trx.schema.alterTable("killmailBattle", (table) => { | ||
table.dropForeign("killmail"); | ||
}); | ||
await trx.schema.alterTable("killmailBattle", (table) => { | ||
table.foreign("killmail").references("killmail.id").onDelete("CASCADE"); | ||
}); | ||
|
||
await trx.schema.alterTable("srpVerdict", (table) => { | ||
table.dropForeign("killmail"); | ||
table.dropForeign("reimbursement"); | ||
}); | ||
await trx.schema.alterTable("srpVerdict", (table) => { | ||
table.foreign("killmail").references("killmail.id").onDelete("CASCADE"); | ||
table | ||
.foreign("reimbursement") | ||
.references("srpReimbursement.id") | ||
.onDelete("SET NULL"); | ||
}); | ||
}; | ||
|
||
exports.down = async function (trx) { | ||
await trx.schema.alterTable("killmailBattle", (table) => { | ||
table.dropForeign("killmail"); | ||
}); | ||
await trx.schema.alterTable("killmailBattle", (table) => { | ||
table.foreign("killmail").references("killmail.id"); | ||
}); | ||
|
||
await trx.schema.alterTable("srpVerdict", (table) => { | ||
table.dropForeign("killmail"); | ||
table.dropForeign("reimbursement"); | ||
}); | ||
await trx.schema.alterTable("srpVerdict", (table) => { | ||
table.foreign("killmail").references("killmail.id"); | ||
table.foreign("reimbursement").references("srpReimbursement.id"); | ||
}); | ||
}; |
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,60 @@ | ||
import { flow } from "../../../util/flow/flow.js"; | ||
import { EsiEndpoint } from "../EsiEndpoint.js"; | ||
import { EsiEndpointParams } from "../fetch/EsiEndpointParams.js"; | ||
import { fetchEsiEx } from "../fetch/fetchEsi.js"; | ||
|
||
/** | ||
* Exposes a paginated ESI endpoint as a flow source | ||
* | ||
* Provided an ESI endpoint that is paginated (i.e. returns an array of data | ||
* split across multiple pages), creates a flow that emits elements in order | ||
* from those pages, advancing pages when necessary. | ||
* | ||
* Respects backpressure, so new pages are only fetched when old ones are | ||
* completely consumed. | ||
*/ | ||
export function paginatedEsiEndpoint<T extends ArrayEsiEndpoint>( | ||
endpoint: T, | ||
params: Omit<EsiEndpointParams<T>, "page">, | ||
maxAttempts = 2, | ||
) { | ||
return flow.defineSource<EndpointRowItem<T>>((node) => { | ||
let nextPage = 1; | ||
let maxPages = 1; | ||
|
||
const activeParams = Object.assign({ page: nextPage }, params); | ||
|
||
return { | ||
async onRead() { | ||
if (nextPage > maxPages) { | ||
node.close(); | ||
return; | ||
} | ||
activeParams.page = nextPage; | ||
|
||
const pageResult = await fetchEsiEx( | ||
endpoint, | ||
activeParams as EsiEndpointParams<T>, | ||
maxAttempts, | ||
); | ||
|
||
maxPages = pageResult.pageCount; | ||
const items = pageResult.data; | ||
for (const item of items) { | ||
node.emit(item); | ||
} | ||
|
||
nextPage++; | ||
}, | ||
}; | ||
}); | ||
} | ||
|
||
interface ArrayEsiEndpoint extends EsiEndpoint { | ||
response: unknown[]; | ||
query: { | ||
page: number; | ||
}; | ||
} | ||
|
||
type EndpointRowItem<T extends ArrayEsiEndpoint> = T["response"][0]; |
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
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
Oops, something went wrong.