Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Filter for only active columns in grapher data download #4242

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

danyx23
Copy link
Contributor

@danyx23 danyx23 commented Dec 2, 2024

Filter data downloads in grapher to only the actively used columns. Not doing this was a problem for csv based explorers that can have a huge number of columns.

@owidbot
Copy link
Contributor

owidbot commented Dec 2, 2024

Quick links (staging server):

Site Dev Site Preview Admin Wizard Docs

Login: ssh owid@staging-site-filter-download-columns

SVG tester:

Number of differences (default views): 0 ✅
Number of differences (all views): 0 ✅

Edited: 2024-12-02 16:28:20 UTC
Execution time: 1.36 seconds

@@ -606,11 +606,30 @@ export class OwidTable extends CoreTable<OwidRow, OwidColumnDef> {
}

// Give our users a clean CSV of each Grapher. Assumes an Owid Table with entityName.
toPrettyCsv(useShortNames: boolean = false): string {
toPrettyCsv(
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty comment

Comment on lines 614 to 627
const activeColumnsDiff: Set<string> = activeColumnSlugs
? differenceOfSets([
new Set(this.columnSlugs),
new Set(activeColumnSlugs),
])
: new Set()
const columnSlugsToRemove = differenceOfSets([
activeColumnsDiff,
new Set([
OwidTableSlugs.year,
OwidTableSlugs.day,
this.entityNameSlug,
]),
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this all would be a bit cleaner and easier to follow if it was using this.select() instead. The two diffs after one another are hard to reason about, after all.

I.e. something like:

if (activeColumnSlugs?.length) {
	this.select([year, day, entityName, ...activeColumnSlugs])
} else {
	this.dropColumns(...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah very nice! I looked a bit to see if we had the inverse of drop and was looking for pick or keep but didn't think of select. Much nicer, thanks!

@danyx23 danyx23 merged commit d251b43 into master Dec 3, 2024
21 checks passed
@danyx23 danyx23 deleted the filter-download-columns branch December 3, 2024 13:24
@marcelgerber marcelgerber changed the title ✨ Filter for only active columsn in grapher data download ✨ Filter for only active columns in grapher data download Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants