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

perf: Do not sort dimensions in View #1041

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/rdf/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export const adminVocabulary = namespace("https://ld.admin.ch/vocabulary/");
export const cube = namespace("https://cube.link/");
export const cubeView = namespace("https://cube.link/view/");
export const cubeMeta = namespace("https://cube.link/meta/");
export const view = namespace("https://cube.link/view/");

export const visualizeAdmin = namespace("https://visualize.admin.ch/");
25 changes: 21 additions & 4 deletions app/rdf/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CubeDimension,
Filter,
LookupSource,
View,
View as RDFView,
} from "rdf-cube-view-query";
import rdf from "rdf-ext";
import { Literal, NamedNode } from "rdf-js";
Expand Down Expand Up @@ -44,6 +44,23 @@ import { loadResourceLiterals } from "./query-literals";
import { loadUnversionedResources } from "./query-sameas";
import { loadUnits } from "./query-unit-labels";

// FIXME: Remove once sorting is removed (https://github.com/zazuko/rdf-cube-view-query/pull/96)
const View = RDFView;
View.prototype.setDefaultColumns = function () {
const orderingColumns = this.dimensions.map((dimension) => ({
// @ts-ignore
iri: dimension.cubeDimensions[0].path.value,
term: dimension.ptr.term,
}));

const projectionPtr = this.ptr.out(ns.view.projection);
projectionPtr.addList(
ns.view.columns,
// @ts-ignore
orderingColumns.map((dimension) => dimension.term)
);
};

const DIMENSION_VALUE_UNDEFINED = ns.cube.Undefined.value;

/** Adds a suffix to an iri to mark its label */
Expand Down Expand Up @@ -598,7 +615,7 @@ const buildFilters = ({
locale,
}: {
cube: Cube;
view: View;
view: RDFView;
filters: Filters;
locale: string;
}): Filter[] => {
Expand Down Expand Up @@ -698,7 +715,7 @@ async function fetchViewObservations({
disableDistinct,
}: {
limit: number | undefined;
observationsView: View;
observationsView: RDFView;
disableDistinct: boolean;
}) {
/**
Expand Down Expand Up @@ -783,7 +800,7 @@ function buildDimensions({
observationFilters,
raw,
}: {
cubeView: View;
cubeView: RDFView;
dimensions: Maybe<string[]>;
cubeDimensions: ResolvedDimension[];
cube: Cube;
Expand Down
1 change: 1 addition & 0 deletions app/typings/rdf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ declare module "rdf-cube-view-query" {
}): Promise<Record<string, Literal | NamedNode>[]>;
addDimension(dimension: Dimension): View;
createDimension(options: $FixMe): Dimension;
setDefaultColumns(): void;
}
export class Source extends Node {
constructor(
Expand Down