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 16, 2023
1 parent 1d2206a commit 497ec60
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 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/");
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)

This comment has been minimized.

Copy link
@Rdataflow

Rdataflow May 31, 2023

Contributor

@bprusinowski 🎉 it's in now 😄

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

0 comments on commit 497ec60

Please sign in to comment.