Skip to content

Commit

Permalink
perf: Do not sort dimensions in View
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed May 15, 2023
1 parent 1d2206a commit 231ce79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
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/");
20 changes: 15 additions & 5 deletions app/rdf/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
CubeDimension,
Filter,
LookupSource,
View,
View as RDFView,
} from "rdf-cube-view-query";
import rdf from "rdf-ext";
import { Literal, NamedNode } from "rdf-js";
import { Literal, NamedNode, Term } from "rdf-js";
import { ParsingClient } from "sparql-http-client/ParsingClient";
import { LRUCache } from "typescript-lru-cache";

Expand Down Expand Up @@ -44,6 +44,16 @@ import { loadResourceLiterals } from "./query-literals";
import { loadUnversionedResources } from "./query-sameas";
import { loadUnits } from "./query-unit-labels";

// FIXME: Remove once sorting is removed from rdf-cube-view-query
const View = RDFView;
View.prototype.setDefaultColumns = function () {
const projectionPtr = this.ptr.out(ns.view.projection);
projectionPtr.addList(
ns.view.columns,
this.dimensions.map((dimension) => dimension.ptr.term as 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 +608,7 @@ const buildFilters = ({
locale,
}: {
cube: Cube;
view: View;
view: RDFView;
filters: Filters;
locale: string;
}): Filter[] => {
Expand Down Expand Up @@ -698,7 +708,7 @@ async function fetchViewObservations({
disableDistinct,
}: {
limit: number | undefined;
observationsView: View;
observationsView: RDFView;
disableDistinct: boolean;
}) {
/**
Expand Down Expand Up @@ -783,7 +793,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

0 comments on commit 231ce79

Please sign in to comment.