From bf0b60ab3af93b19f1dc5d2381675155d141746c Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sun, 26 Jul 2026 18:01:07 +0200 Subject: [PATCH 01/12] =?UTF-8?q?Start=20designing=20the=20database=20sche?= =?UTF-8?q?ma,=20based=20on=20Thomas=E2=80=99=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce a new namespace table, which makes it easy to figure out whether its a group or user account. Signed-off-by: Stefan Marr --- src/backend/db/db.sql | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/backend/db/db.sql b/src/backend/db/db.sql index 189b2012..e15044c6 100644 --- a/src/backend/db/db.sql +++ b/src/backend/db/db.sql @@ -200,6 +200,42 @@ CREATE TABLE Timeline ( foreign key (criterion) references Criterion (id) ); +-- User Accounts +CREATE TABLE Account ( + id serial primary key, + userName varchar unique, -- has to be a valid `slug` + email varchar unique, + passwordHash varchar, + apiToken char(64) NULL, + createdAt timestamp with time zone DEFAULT now(), + isActive bool NOT NULL DEFAULT true -- deactivated users cannot log in +); + +CREATE TABLE Group ( + id serial primary key, + groupName varchar unique, -- has to be a valid `slug` + description text, + createdAt timestamp with time zone DEFAULT now(), + createdBy int REFERENCES Account (id) +); + +-- A Namespace is either a user or group, and ensures that +-- there are no name collisions between users and groups. +CREATE TABLE Namespace ( + id serial primary key, + name varchar unique NOT NULL, -- has to be a valid `slug` + type char(1) CHECK (type IN ('u', 'g')), + accountId int NULL REFERENCES Account (id), + groupId int NULL REFERENCES Group (id), + + CONSTRAINT eitherAccountOrGroup CHECK ( + (accountId IS NOT NULL AND groupId IS NULL AND type = 'u') OR + (accountId IS NULL AND groupId IS NOT NULL AND type = 'g') + ) +); + +TODO: group and project memberships + -- Used by ReBenchDB's perf-tracker, for self-performance tracking CREATE PROCEDURE recordAdditionalMeasurement( aRunId int, From f1c057bf079fd3249911a621addee584940f2d5f Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Tue, 11 Aug 2026 09:23:47 +0100 Subject: [PATCH 02/12] Thinking of namespaces and permissions in the database schema Signed-off-by: Stefan Marr --- src/backend/db/db.sql | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/backend/db/db.sql b/src/backend/db/db.sql index e15044c6..70811880 100644 --- a/src/backend/db/db.sql +++ b/src/backend/db/db.sql @@ -49,7 +49,9 @@ CREATE TABLE Project ( position integer DEFAULT 0, -- the bases for comparisons that we generate when a experiment is completed - baseBranch varchar + baseBranch varchar, + + namespaceId int NOT NULL REFERENCES Namespace (id) ); -- Identifies the specific state of the source, the code, on which @@ -229,11 +231,28 @@ CREATE TABLE Namespace ( groupId int NULL REFERENCES Group (id), CONSTRAINT eitherAccountOrGroup CHECK ( - (accountId IS NOT NULL AND groupId IS NULL AND type = 'u') OR - (accountId IS NULL AND groupId IS NOT NULL AND type = 'g') + (accountId IS NOT NULL AND groupId IS NULL AND type = 'u') OR + (accountId IS NULL AND groupId IS NOT NULL AND type = 'g') ) ); +ALTER TABLE Account + ADD COLUMN namespaceId int REFERENCES Namespace (id); +ALTER TABLE Group + ADD COLUMN namespaceId int REFERENCES Namespace (id); + +CREATE TYPE projectRole AS ENUM ('view', 'edit', 'owner'); + +CREATE TABLE ProjectPermissions ( + projectId int REFERENCES Project (id), + namespaceId int REFERENCES Namespace (id), + role projectRole NOT NULL, + PRIMARY KEY (projectId, namespaceId) +); + + + + TODO: group and project memberships -- Used by ReBenchDB's perf-tracker, for self-performance tracking From 8d670e900a86901741e2d9d75ad785fb0a68665c Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 4 Sep 2026 23:20:30 +0200 Subject: [PATCH 03/12] =?UTF-8?q?Work=20In=20Progress=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Marr --- src/backend/db/db.sql | 48 +++++++++---- src/backend/db/db.ts | 57 +++++++++++----- .../db/schema-updates/migration.016.sql | 49 ++++++++++++++ src/backend/project/project.ts | 21 +++++- src/backend/timeline/timeline.ts | 5 +- src/backend/util.ts | 11 +-- src/index.ts | 67 +++++++++++-------- 7 files changed, 191 insertions(+), 67 deletions(-) create mode 100644 src/backend/db/schema-updates/migration.016.sql diff --git a/src/backend/db/db.sql b/src/backend/db/db.sql index 70811880..6bdcaf29 100644 --- a/src/backend/db/db.sql +++ b/src/backend/db/db.sql @@ -51,9 +51,32 @@ CREATE TABLE Project ( -- the bases for comparisons that we generate when a experiment is completed baseBranch varchar, - namespaceId int NOT NULL REFERENCES Namespace (id) + namespaceId int -- will add REFERENCES Namespace (id) once we defined the table + -- TODO: add NOT NULL ); +-- TODO: which way do I want to approach this? +-- while introducing namespaces, do I go with a default namespace for existing projects, +-- like a specifically chosen user, or do I use a named legacy "global" namespace that is handled differently, +-- or do I have it be NULL, which is kind of the legacy global namespace. +-- I think, for my own sanity, and for the effort it takes to implement all this, +-- I should probably just go and assign all existing projects to a specific user. +-- Though, at the very least this also means I need to make sure that when I add data, that's theres the user info. +-- And that also applies to the performance self-tracking feature. + + +-- New Thoughts: +-- I think the effort of backwards compatibility is small and will make the transition easier. +-- Specifically, it will allow me to minimize the code changes in the early phase. +-- By having a small number of redirects and default values, +-- we should be able to attribute each project to a specific namespace. + +-- I'll create the "legacy" group as a start. +-- I'll also create the "admin" user, which will be the owner of the legacy group. +-- All projects without namespace, i.e., namespaceId is NULL, will be assigned to the legacy group. +-- All requests without namespace will be redirected to the legacy group. + + -- Identifies the specific state of the source, the code, on which -- an experiment and its measurements are based. CREATE TABLE Source ( @@ -203,7 +226,7 @@ CREATE TABLE Timeline ( ); -- User Accounts -CREATE TABLE Account ( +CREATE TABLE UserAccount ( id serial primary key, userName varchar unique, -- has to be a valid `slug` email varchar unique, @@ -213,22 +236,22 @@ CREATE TABLE Account ( isActive bool NOT NULL DEFAULT true -- deactivated users cannot log in ); -CREATE TABLE Group ( +CREATE TABLE UserGroup ( id serial primary key, groupName varchar unique, -- has to be a valid `slug` description text, createdAt timestamp with time zone DEFAULT now(), - createdBy int REFERENCES Account (id) + createdBy int REFERENCES UserAccount (id) ); --- A Namespace is either a user or group, and ensures that +-- A Namespace is either a user account or user group, and ensures that -- there are no name collisions between users and groups. CREATE TABLE Namespace ( id serial primary key, name varchar unique NOT NULL, -- has to be a valid `slug` type char(1) CHECK (type IN ('u', 'g')), - accountId int NULL REFERENCES Account (id), - groupId int NULL REFERENCES Group (id), + accountId int NULL REFERENCES UserAccount (id), + groupId int NULL REFERENCES UserGroup (id), CONSTRAINT eitherAccountOrGroup CHECK ( (accountId IS NOT NULL AND groupId IS NULL AND type = 'u') OR @@ -236,9 +259,11 @@ CREATE TABLE Namespace ( ) ); -ALTER TABLE Account +ALTER TABLE Project + ADD CONSTRAINT fk_namespace FOREIGN KEY (namespaceId) REFERENCES Namespace (id); +ALTER TABLE UserAccount ADD COLUMN namespaceId int REFERENCES Namespace (id); -ALTER TABLE Group +ALTER TABLE UserGroup ADD COLUMN namespaceId int REFERENCES Namespace (id); CREATE TYPE projectRole AS ENUM ('view', 'edit', 'owner'); @@ -250,11 +275,6 @@ CREATE TABLE ProjectPermissions ( PRIMARY KEY (projectId, namespaceId) ); - - - -TODO: group and project memberships - -- Used by ReBenchDB's perf-tracker, for self-performance tracking CREATE PROCEDURE recordAdditionalMeasurement( aRunId int, diff --git a/src/backend/db/db.ts b/src/backend/db/db.ts index c95d31be..a01114b3 100644 --- a/src/backend/db/db.ts +++ b/src/backend/db/db.ts @@ -16,7 +16,7 @@ import { FullPlotData, TimelineSuite } from '../../shared/api.js'; -import { robustPath, TotalCriterion } from '../util.js'; +import { legacyGroupName, robustPath, TotalCriterion } from '../util.js'; import { assert } from '../logging.js'; import { simplifyCmdline } from '../../shared/util.js'; import type { SummaryStatistics } from '../../shared/stats.js'; @@ -312,14 +312,20 @@ export abstract class Database { return cache.get(cacheKey); } - const result = await this.query(insertUnionFetchQ); - assert( - result.rowCount === 1, - 'recordCached insertUnionFetchQ did not return exactly one row. ' + - 'rowCount: ${result.rowCount}' - ); - cache.set(cacheKey, result.rows[0]); - return result.rows[0]; + try { + const result = await this.query(insertUnionFetchQ); + assert( + result.rowCount === 1, + 'recordCached insertUnionFetchQ did not return exactly one row. ' + + 'rowCount: ${result.rowCount}' + ); + cache.set(cacheKey, result.rows[0]); + return result.rows[0]; + } catch (e: any) { + e.rebenchdbQuery = insertUnionFetchQ; + console.log({ e }); + throw e; + } } public async getBenchmarksByProjectId(projectId: number): Promise< @@ -493,16 +499,35 @@ export abstract class Database { }); } - public async getProjectBySlug( + public async getProjectBySlugs( + namespaceSlug: string, projectNameSlug: string ): Promise { - const q = { - name: 'fetchProjectBySlugName', - text: `SELECT * FROM Project - WHERE lower($1) = lower(slug)`, - values: [projectNameSlug] - }; + let q: any; + + if (namespaceSlug === legacyGroupName) { + q = { + name: 'fetchProjectBySlugNameLegacy', + text: `SELECT p.* + FROM Project p + WHERE lower($1) = lower(p.slug) + AND p.namespaceId IS NULL`, + values: [projectNameSlug] + }; + } else { + q = { + name: 'fetchProjectBySlugName', + text: `SELECT p.* + FROM Project p + JOIN Namespace n ON p.namespaceId = n.id + WHERE lower($2) = lower(p.slug) + AND lower($1) = lower(n.name)`, + values: [namespaceSlug, projectNameSlug] + }; + } + console.log(q.text); + console.log({ q }); const result = await this.query(q); if (result.rowCount !== 1) { diff --git a/src/backend/db/schema-updates/migration.016.sql b/src/backend/db/schema-updates/migration.016.sql new file mode 100644 index 00000000..48bae635 --- /dev/null +++ b/src/backend/db/schema-updates/migration.016.sql @@ -0,0 +1,49 @@ +-- Adding Support for Users, Groups, and Namespaces +CREATE TABLE UserAccount ( + id serial primary key, + userName varchar unique, -- has to be a valid `slug` + email varchar unique, + passwordHash varchar, + apiToken char(64) NULL, + createdAt timestamp with time zone DEFAULT now(), + isActive bool NOT NULL DEFAULT true -- deactivated users cannot log in +); + +CREATE TABLE UserGroup ( + id serial primary key, + groupName varchar unique, -- has to be a valid `slug` + description text, + createdAt timestamp with time zone DEFAULT now(), + createdBy int REFERENCES UserAccount (id) +); + +-- A Namespace is either a user account or user group, and ensures that +-- there are no name collisions between users and groups. +CREATE TABLE Namespace ( + id serial primary key, + name varchar unique NOT NULL, -- has to be a valid `slug` + type char(1) CHECK (type IN ('u', 'g')), + accountId int NULL REFERENCES UserAccount (id), + groupId int NULL REFERENCES UserGroup (id), + + CONSTRAINT eitherAccountOrGroup CHECK ( + (accountId IS NOT NULL AND groupId IS NULL AND type = 'u') OR + (accountId IS NULL AND groupId IS NOT NULL AND type = 'g') + ) +); + +ALTER TABLE Project + ADD COLUMN namespaceId int REFERENCES Namespace (id); +ALTER TABLE UserAccount + ADD COLUMN namespaceId int REFERENCES Namespace (id); +ALTER TABLE UserGroup + ADD COLUMN namespaceId int REFERENCES Namespace (id); + +CREATE TYPE projectRole AS ENUM ('view', 'edit', 'owner'); + +CREATE TABLE ProjectPermissions ( + projectId int REFERENCES Project (id), + namespaceId int REFERENCES Namespace (id), + role projectRole NOT NULL, + PRIMARY KEY (projectId, namespaceId) +); diff --git a/src/backend/project/project.ts b/src/backend/project/project.ts index fa30cb30..94489ecf 100644 --- a/src/backend/project/project.ts +++ b/src/backend/project/project.ts @@ -10,16 +10,28 @@ import { } from '../perf-tracker.js'; import { getExpData } from './data-export.js'; import { Database } from '../db/db.js'; -import { rebenchVersion, robustPath } from '../../backend/util.js'; +import { + legacyGroupName, + rebenchVersion, + robustPath +} from '../../backend/util.js'; import { Source } from '../db/types.js'; +/** @deprecated This is support for urls without the namespace slug. */ +export function redirectToLegacyProjectPage(ctx: ParameterizedContext): void { + ctx.redirect(`/${legacyGroupName}/${ctx.params.projectSlug}`); +} + const projectHtml = prepareTemplate(robustPath('backend/project/project.html')); export async function renderProjectPage( ctx: ParameterizedContext, db: Database ): Promise { - const project = await db.getProjectBySlug(ctx.params.projectSlug); + const project = await db.getProjectBySlugs( + ctx.params.namespaceSlug, + ctx.params.projectSlug + ); if (project) { ctx.body = projectHtml({ ...project, rebenchVersion }); ctx.type = 'html'; @@ -57,7 +69,10 @@ export async function renderProjectDataPage( ctx: ParameterizedContext, db: Database ): Promise { - const project = await db.getProjectBySlug(ctx.params.projectSlug); + const project = await db.getProjectBySlugs( + ctx.params.namespaceSlug, + ctx.params.projectSlug + ); if (project) { ctx.body = projectDataTpl({ project, rebenchVersion }); ctx.type = 'html'; diff --git a/src/backend/timeline/timeline.ts b/src/backend/timeline/timeline.ts index 631aa140..d4376e6f 100644 --- a/src/backend/timeline/timeline.ts +++ b/src/backend/timeline/timeline.ts @@ -41,7 +41,10 @@ export async function renderTimeline( ctx: ParameterizedContext, db: Database ): Promise { - const project = await db.getProjectBySlug(ctx.params.projectSlug); + const project = await db.getProjectBySlugs( + ctx.params.namespaceSlug, + ctx.params.projectSlug + ); if (project) { ctx.body = timelineTpl({ diff --git a/src/backend/util.ts b/src/backend/util.ts index d69bee1a..f63d80ba 100644 --- a/src/backend/util.ts +++ b/src/backend/util.ts @@ -28,10 +28,10 @@ const __dirname = getDirname(import.meta.url); * Get a robust path, relative to the source directory. */ export const robustPath = __dirname.includes('dist/') - ? function (path) { + ? function (path: string) { return resolve(`${__dirname}/../../../src/${path}`); } - : function (path) { + : function (path: string) { return resolve(`${__dirname}/../${path}`); }; @@ -39,10 +39,10 @@ export const robustPath = __dirname.includes('dist/') * Get a robust path in the compiled source directory. */ export const robustSrcPath = __dirname.includes('dist/') - ? function (path) { + ? function (path: string) { return `${__dirname}/../${path}`; } - : function (path) { + : function (path: string) { return `${__dirname}/../../dist/src/${path}`; }; @@ -67,6 +67,9 @@ const reportsUrl = process.env.REPORTS_URL || '/static/reports'; const staticUrl = process.env.STATIC_URL || '/static'; const publicUrl = process.env.PUBLIC_URL || _rebench_dev; +// Backwards Compatibility Support for users/groups +export const legacyGroupName = process.env.RDB_LEGACY_GROUP_NAME || 'legacy'; + // configuration for data export is a little more involved, // because the database might run elsewhere, but may produce // data files, which we need to be able to serve, at least in the dev mode. diff --git a/src/index.ts b/src/index.ts index c86e9601..bc319530 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,7 @@ import { } from './backend/main/main.js'; import { getSourceAsJson, + redirectToLegacyProjectPage, renderDataExport, renderProjectDataPage, renderProjectPage @@ -117,25 +118,15 @@ router.post('/runners', koaBody({ urlencoded: true }), async (ctx) => renderRunners(ctx, runnerCache, pipelinesCache) ); -router.get('/:projectSlug', async (ctx) => renderProjectPage(ctx, db)); -defineRoute('/:projectSlug/source/:sourceId', router, db, getSourceAsJson); -router.get('/:projectSlug/timeline', async (ctx) => renderTimeline(ctx, db)); -router.get('/:projectSlug/data', async (ctx) => renderProjectDataPage(ctx, db)); -router.get('/:projectSlug/data/:expIdAndExtension', async (ctx) => { - if ( - ctx.header['X-Purpose'] === 'preview' || - ctx.header['Purpose'] === 'prefetch' || - ctx.header['X-Moz'] === 'prefetch' - ) { - ctx.set('Cache-Control', 'must-revalidate'); - ctx.status = 425; // HTTP Code for 'Too Early' - return; - } - return renderDataExport(ctx, db); -}); -router.get('/:projectSlug/compare/:baseline..:change', async (ctx) => - renderComparePage(ctx, db) -); +if (DEV) { + router.get(`${siteConfig.staticUrl}/*filename`, serveStaticResource); + router.get(`/shared/*filename`, serveStaticSharedResource); + router.get(`/src/frontend/*filename`, serveViewJs); + router.get( + `${siteConfig.reportsUrl}/:change/figure-html/:filename`, + serveReport + ); +} // TODO: rename this to say that this endpoint gets the last 100 measurements // for the project @@ -189,16 +180,6 @@ router.post( deleteCachedReport ); -if (DEV) { - router.get(`${siteConfig.staticUrl}/*filename`, serveStaticResource); - router.get(`/shared/*filename`, serveStaticSharedResource); - router.get(`/src/frontend/*filename`, serveViewJs); - router.get( - `${siteConfig.reportsUrl}/:change/figure-html/:filename`, - serveReport - ); -} - // curl -X OPTIONS http://localhost:33333/rebenchdb/results -i router.options('/rebenchdb/results', reportResultApiVersion); @@ -217,6 +198,34 @@ router.put('/rebenchdb/completion', koaBody(), async (ctx) => handleReBenchCompletion(ctx, db) ); +// all the generic routes with variables need to come after +// the fixed special-purpose routes. Otherwise, the generic +// routes will match first. +router.get('/:namespaceSlug/:projectSlug', async (ctx) => + renderProjectPage(ctx, db) +); +router.get('/:projectSlug', async (ctx) => redirectToLegacyProjectPage(ctx)); + +// TODO: need to be adapted still +defineRoute('/:projectSlug/source/:sourceId', router, db, getSourceAsJson); +router.get('/:projectSlug/timeline', async (ctx) => renderTimeline(ctx, db)); +router.get('/:projectSlug/data', async (ctx) => renderProjectDataPage(ctx, db)); +router.get('/:projectSlug/data/:expIdAndExtension', async (ctx) => { + if ( + ctx.header['X-Purpose'] === 'preview' || + ctx.header['Purpose'] === 'prefetch' || + ctx.header['X-Moz'] === 'prefetch' + ) { + ctx.set('Cache-Control', 'must-revalidate'); + ctx.status = 425; // HTTP Code for 'Too Early' + return; + } + return renderDataExport(ctx, db); +}); +router.get('/:projectSlug/compare/:baseline..:change', async (ctx) => + renderComparePage(ctx, db) +); + app.use(router.routes()); app.use(router.allowedMethods()); From 8f0aa77e59ca96cc8aa647a2bc50ddff94df5970 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Wed, 14 Oct 2026 13:27:59 +0200 Subject: [PATCH 04/12] Disable denoise in integration test Signed-off-by: Stefan Marr --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 835cf416..d8766dfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: # run integration tests pushd tests/rebench-integration - rebench --experiment IntegrationTest rebench.conf + rebench --no-denoise --experiment IntegrationTest rebench.conf sleep 1 PROJID=$(curl -s http://localhost:33333/ReBenchDB-integration-test/data | grep project-id | grep -o -E '[0-9]+') From 7c265067503170051c34a327b815cdbae96e6d26 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Wed, 14 Oct 2026 13:36:10 +0200 Subject: [PATCH 05/12] [Hack] Allow null for denoise data Signed-off-by: Stefan Marr --- src/shared/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/api.ts b/src/shared/api.ts index 3bf2ba52..8e655aaf 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -118,7 +118,7 @@ export interface Environment { /** * Settings reported by `rebench-denoise`. */ - denoise?: Record; + denoise?: Record | null; } export interface BenchmarkData { From 3653c608bcb7a519bcd6203d3ed8a600ab87f1c9 Mon Sep 17 00:00:00 2001 From: benjaminbucan Date: Mon, 26 Oct 2026 23:02:30 +0100 Subject: [PATCH 06/12] Create legacy namespaces and redirect old URLs. Projects are assigned to the legacy namespace. --- src/backend/db/db.sql | 46 +++++++-------- src/backend/db/db.ts | 53 +++++++---------- .../db/schema-updates/migration.016.sql | 26 +++++++++ src/backend/db/types.ts | 5 ++ src/backend/project/project.ts | 5 ++ src/index.ts | 57 ++++++++++++------- tests/backend/project/project.test.ts | 8 ++- 7 files changed, 121 insertions(+), 79 deletions(-) diff --git a/src/backend/db/db.sql b/src/backend/db/db.sql index 6bdcaf29..5db133c9 100644 --- a/src/backend/db/db.sql +++ b/src/backend/db/db.sql @@ -51,32 +51,9 @@ CREATE TABLE Project ( -- the bases for comparisons that we generate when a experiment is completed baseBranch varchar, - namespaceId int -- will add REFERENCES Namespace (id) once we defined the table - -- TODO: add NOT NULL + namespaceId int NOT NULL -- foreign key is added below ); --- TODO: which way do I want to approach this? --- while introducing namespaces, do I go with a default namespace for existing projects, --- like a specifically chosen user, or do I use a named legacy "global" namespace that is handled differently, --- or do I have it be NULL, which is kind of the legacy global namespace. --- I think, for my own sanity, and for the effort it takes to implement all this, --- I should probably just go and assign all existing projects to a specific user. --- Though, at the very least this also means I need to make sure that when I add data, that's theres the user info. --- And that also applies to the performance self-tracking feature. - - --- New Thoughts: --- I think the effort of backwards compatibility is small and will make the transition easier. --- Specifically, it will allow me to minimize the code changes in the early phase. --- By having a small number of redirects and default values, --- we should be able to attribute each project to a specific namespace. - --- I'll create the "legacy" group as a start. --- I'll also create the "admin" user, which will be the owner of the legacy group. --- All projects without namespace, i.e., namespaceId is NULL, will be assigned to the legacy group. --- All requests without namespace will be redirected to the legacy group. - - -- Identifies the specific state of the source, the code, on which -- an experiment and its measurements are based. CREATE TABLE Source ( @@ -260,7 +237,7 @@ CREATE TABLE Namespace ( ); ALTER TABLE Project - ADD CONSTRAINT fk_namespace FOREIGN KEY (namespaceId) REFERENCES Namespace (id); + ADD FOREIGN KEY (namespaceId) REFERENCES Namespace (id); ALTER TABLE UserAccount ADD COLUMN namespaceId int REFERENCES Namespace (id); ALTER TABLE UserGroup @@ -275,6 +252,25 @@ CREATE TABLE ProjectPermissions ( PRIMARY KEY (projectId, namespaceId) ); +-- The admin account owns the legacy group. +-- Because Authentication is not yet implemented, the admin account has no password hash, so it cannot log in. +INSERT INTO UserAccount (userName) VALUES ('admin'); +INSERT INTO Namespace (name, type, accountId) + SELECT userName, 'u', id FROM UserAccount WHERE userName = 'admin'; +UPDATE UserAccount + SET namespaceId = (SELECT id FROM Namespace WHERE name = 'admin') + WHERE userName = 'admin'; + +-- Old projects that were created before users and groups existed belong to the legacy group. +INSERT INTO UserGroup (groupName, description, createdBy) + SELECT 'legacy', 'Projects created before users and groups existed', id + FROM UserAccount WHERE userName = 'admin'; +INSERT INTO Namespace (name, type, groupId) + SELECT groupName, 'g', id FROM UserGroup WHERE groupName = 'legacy'; +UPDATE UserGroup + SET namespaceId = (SELECT id FROM Namespace WHERE name = 'legacy') + WHERE groupName = 'legacy'; + -- Used by ReBenchDB's perf-tracker, for self-performance tracking CREATE PROCEDURE recordAdditionalMeasurement( aRunId int, diff --git a/src/backend/db/db.ts b/src/backend/db/db.ts index a01114b3..17e48447 100644 --- a/src/backend/db/db.ts +++ b/src/backend/db/db.ts @@ -28,6 +28,7 @@ import type { MeasurementData, Metadata, Project, + ProjectWithNamespace, RevisionComparison, RevisionData, Run, @@ -487,48 +488,35 @@ export abstract class Database { return this.recordCached(this.projects, projectName, { name: 'insertOrFetchProjectByName', text: `WITH insertedRow AS ( - INSERT INTO Project (name, slug) - VALUES ($1, regexp_replace($2, '[^0-9a-zA-Z-]', '-', 'g')) + INSERT INTO Project (name, slug, namespaceId) + SELECT $1, + regexp_replace($2, '[^0-9a-zA-Z-]', '-', 'g'), + n.id + FROM Namespace n + WHERE n.name = $3 ON CONFLICT DO NOTHING RETURNING * ) SELECT * FROM insertedRow UNION ALL SELECT * FROM Project WHERE name = $1;`, - values: [projectName, projectName] + values: [projectName, projectName, legacyGroupName] }); } public async getProjectBySlugs( namespaceSlug: string, - projectNameSlug: string - ): Promise { - let q: any; - - if (namespaceSlug === legacyGroupName) { - q = { - name: 'fetchProjectBySlugNameLegacy', - text: `SELECT p.* - FROM Project p - WHERE lower($1) = lower(p.slug) - AND p.namespaceId IS NULL`, - values: [projectNameSlug] - }; - } else { - q = { - name: 'fetchProjectBySlugName', - text: `SELECT p.* + projectSlug: string + ): Promise { + const result = await this.query({ + name: 'fetchProjectByNamespaceAndSlug', + text: `SELECT p.*, n.name AS namespacename FROM Project p JOIN Namespace n ON p.namespaceId = n.id - WHERE lower($2) = lower(p.slug) - AND lower($1) = lower(n.name)`, - values: [namespaceSlug, projectNameSlug] - }; - } - - console.log(q.text); - console.log({ q }); - const result = await this.query(q); + WHERE lower(n.name) = lower($1) + AND lower(p.slug) = lower($2)`, + values: [namespaceSlug, projectSlug] + }); if (result.rowCount !== 1) { return undefined; @@ -561,10 +549,13 @@ export abstract class Database { }); } - public async getAllProjects(): Promise { + public async getAllProjects(): Promise { const result = await this.query({ name: 'fetchAllProjects', - text: 'SELECT * FROM Project ORDER BY position DESC' + text: `SELECT p.*, n.name AS namespacename + FROM Project p + JOIN Namespace n ON p.namespaceId = n.id + ORDER BY p.position DESC` }); return result.rows; } diff --git a/src/backend/db/schema-updates/migration.016.sql b/src/backend/db/schema-updates/migration.016.sql index 48bae635..9f766184 100644 --- a/src/backend/db/schema-updates/migration.016.sql +++ b/src/backend/db/schema-updates/migration.016.sql @@ -47,3 +47,29 @@ CREATE TABLE ProjectPermissions ( role projectRole NOT NULL, PRIMARY KEY (projectId, namespaceId) ); + +-- The admin account owns the legacy group. +-- Because Authentication is not yet implemented, the admin account has no password hash, so it cannot log in. +INSERT INTO UserAccount (userName) VALUES ('admin'); +INSERT INTO Namespace (name, type, accountId) + SELECT userName, 'u', id FROM UserAccount WHERE userName = 'admin'; +UPDATE UserAccount + SET namespaceId = (SELECT id FROM Namespace WHERE name = 'admin') + WHERE userName = 'admin'; + +-- Old projects that were created before users and groups existed belong to the legacy group. +INSERT INTO UserGroup (groupName, description, createdBy) + SELECT 'legacy', 'Projects created before users and groups existed', id + FROM UserAccount WHERE userName = 'admin'; +INSERT INTO Namespace (name, type, groupId) + SELECT groupName, 'g', id FROM UserGroup WHERE groupName = 'legacy'; +UPDATE UserGroup + SET namespaceId = (SELECT id FROM Namespace WHERE name = 'legacy') + WHERE groupName = 'legacy'; + + +-- Update all existing projects to belong to the legacy group, +-- and make the namespaceId column non-nullable. +UPDATE Project + SET namespaceId = (SELECT id FROM Namespace WHERE name = 'legacy'); +ALTER TABLE Project ALTER COLUMN namespaceId SET NOT NULL; diff --git a/src/backend/db/types.ts b/src/backend/db/types.ts index eebaf4b7..d7a4452d 100644 --- a/src/backend/db/types.ts +++ b/src/backend/db/types.ts @@ -72,6 +72,11 @@ export interface Project { allresults: boolean; githubnotification: boolean; basebranch: string; + namespaceid: number; +} + +export interface ProjectWithNamespace extends Project { + namespacename: string; } export interface Source { diff --git a/src/backend/project/project.ts b/src/backend/project/project.ts index 94489ecf..c7c0befc 100644 --- a/src/backend/project/project.ts +++ b/src/backend/project/project.ts @@ -22,6 +22,11 @@ export function redirectToLegacyProjectPage(ctx: ParameterizedContext): void { ctx.redirect(`/${legacyGroupName}/${ctx.params.projectSlug}`); } +/** Supports URLs that predate namespaces. */ +export function redirectToLegacyNamespace(ctx: ParameterizedContext): void { + ctx.redirect(`/${legacyGroupName}${ctx.url}`); +} + const projectHtml = prepareTemplate(robustPath('backend/project/project.html')); export async function renderProjectPage( diff --git a/src/index.ts b/src/index.ts index bc319530..611376b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,7 +21,7 @@ import { } from './backend/main/main.js'; import { getSourceAsJson, - redirectToLegacyProjectPage, + redirectToLegacyNamespace, renderDataExport, renderProjectDataPage, renderProjectPage @@ -201,29 +201,46 @@ router.put('/rebenchdb/completion', koaBody(), async (ctx) => // all the generic routes with variables need to come after // the fixed special-purpose routes. Otherwise, the generic // routes will match first. -router.get('/:namespaceSlug/:projectSlug', async (ctx) => - renderProjectPage(ctx, db) + +// These routes are for legacy URLs that predate namespaces. +router.get('/:projectSlug', redirectToLegacyNamespace); +router.get('/:projectSlug/timeline', redirectToLegacyNamespace); +router.get('/:projectSlug/data', redirectToLegacyNamespace); +router.get('/:projectSlug/data/:expIdAndExtension', redirectToLegacyNamespace); +router.get( + '/:projectSlug/compare/:baseline..:change', + redirectToLegacyNamespace ); -router.get('/:projectSlug', async (ctx) => redirectToLegacyProjectPage(ctx)); -// TODO: need to be adapted still defineRoute('/:projectSlug/source/:sourceId', router, db, getSourceAsJson); -router.get('/:projectSlug/timeline', async (ctx) => renderTimeline(ctx, db)); -router.get('/:projectSlug/data', async (ctx) => renderProjectDataPage(ctx, db)); -router.get('/:projectSlug/data/:expIdAndExtension', async (ctx) => { - if ( - ctx.header['X-Purpose'] === 'preview' || - ctx.header['Purpose'] === 'prefetch' || - ctx.header['X-Moz'] === 'prefetch' - ) { - ctx.set('Cache-Control', 'must-revalidate'); - ctx.status = 425; // HTTP Code for 'Too Early' - return; + +router.get('/:namespaceSlug/:projectSlug', async (ctx) => + renderProjectPage(ctx, db) +); +router.get('/:namespaceSlug/:projectSlug/timeline', async (ctx) => + renderTimeline(ctx, db) +); +router.get('/:namespaceSlug/:projectSlug/data', async (ctx) => + renderProjectDataPage(ctx, db) +); +router.get( + '/:namespaceSlug/:projectSlug/data/:expIdAndExtension', + async (ctx) => { + if ( + ctx.header['X-Purpose'] === 'preview' || + ctx.header['Purpose'] === 'prefetch' || + ctx.header['X-Moz'] === 'prefetch' + ) { + ctx.set('Cache-Control', 'must-revalidate'); + ctx.status = 425; // HTTP Code 425 Too Early + return; + } + return renderDataExport(ctx, db); } - return renderDataExport(ctx, db); -}); -router.get('/:projectSlug/compare/:baseline..:change', async (ctx) => - renderComparePage(ctx, db) +); +router.get( + '/:namespaceSlug/:projectSlug/compare/:baseline..:change', + async (ctx) => renderComparePage(ctx, db) ); app.use(router.routes()); diff --git a/tests/backend/project/project.test.ts b/tests/backend/project/project.test.ts index ccab8671..7ed58f90 100644 --- a/tests/backend/project/project.test.ts +++ b/tests/backend/project/project.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from '@jest/globals'; import { initJestMatchers } from '../../helpers.js'; -import { Project } from '../../../src/backend/db/types.js'; +import { ProjectWithNamespace } from '../../../src/backend/db/types.js'; import { prepareTemplate } from '../../../src/backend/templates.js'; import { robustPath } from '../../../src/backend/util.js'; @@ -8,7 +8,7 @@ initJestMatchers(); describe('renderProjectDataPage', () => { it('should render the page', () => { - const project: Project = { + const project: ProjectWithNamespace = { id: 1, name: 'Test Project', slug: 'test-project', @@ -17,7 +17,9 @@ describe('renderProjectDataPage', () => { showchanges: true, allresults: true, githubnotification: false, - basebranch: 'base' + basebranch: 'base', + namespaceid: 1, + namespacename: 'legacy' }; const tpl = prepareTemplate( From 0db01583086a4ace32c55f206a7745755926bbe1 Mon Sep 17 00:00:00 2001 From: benjaminbucan Date: Mon, 26 Oct 2026 23:11:09 +0100 Subject: [PATCH 07/12] Trigger CI From 4ed9de06ef7726b33e7ed68bd1630857c4d14be7 Mon Sep 17 00:00:00 2001 From: benjaminbucan Date: Tue, 27 Oct 2026 15:58:55 +0100 Subject: [PATCH 08/12] CI follows redirects --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8766dfa..343f213a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,12 +102,12 @@ jobs: rebench --no-denoise --experiment IntegrationTest rebench.conf sleep 1 - PROJID=$(curl -s http://localhost:33333/ReBenchDB-integration-test/data | grep project-id | grep -o -E '[0-9]+') - EXPID=$(curl -s http://localhost:33333/rebenchdb/dash/$PROJID/data-overview | jq '.data[0].expid') + PROJID=$(curl -sL http://localhost:33333/ReBenchDB-integration-test/data | grep project-id | grep -o -E '[0-9]+') + EXPID=$(curl -sL http://localhost:33333/rebenchdb/dash/$PROJID/data-overview | jq '.data[0].expid') # Trigger data generation - curl -s http://localhost:33333/ReBenchDB-integration-test/data/$EXPID.json.gz > /dev/null - curl -s http://localhost:33333/ReBenchDB-integration-test/data/$EXPID.csv.gz > /dev/null + curl -sL http://localhost:33333/ReBenchDB-integration-test/data/$EXPID.json.gz > /dev/null + curl -sL http://localhost:33333/ReBenchDB-integration-test/data/$EXPID.csv.gz > /dev/null sleep 10 # give the server some time to generate the files # reposses the files to be able to read them From e0f2a5ac9ea5a978fdcb2b7243d364884f911f8d Mon Sep 17 00:00:00 2001 From: benjaminbucan Date: Tue, 10 Nov 2026 17:20:37 +0100 Subject: [PATCH 09/12] Rename migration 016 to 021 --- .../db/schema-updates/{migration.016.sql => migration.021.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/backend/db/schema-updates/{migration.016.sql => migration.021.sql} (100%) diff --git a/src/backend/db/schema-updates/migration.016.sql b/src/backend/db/schema-updates/migration.021.sql similarity index 100% rename from src/backend/db/schema-updates/migration.016.sql rename to src/backend/db/schema-updates/migration.021.sql From d70663cbae08a8c3f5fda237a5ffd03761392c98 Mon Sep 17 00:00:00 2001 From: benjaminbucan Date: Tue, 10 Nov 2026 17:25:16 +0100 Subject: [PATCH 10/12] Add namespace to project links --- src/backend/main/index.html | 5 +++-- src/backend/project/project-data.html | 1 + src/backend/project/project.html | 5 +++-- src/frontend/project-data.ts | 3 ++- src/frontend/render.ts | 10 ++++++---- tests/data/expected-results/main/index.html | 5 +++-- tests/data/expected-results/project/project-data.html | 1 + 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/backend/main/index.html b/src/backend/main/index.html index 5e896141..a02fcb5d 100644 --- a/src/backend/main/index.html +++ b/src/backend/main/index.html @@ -31,13 +31,14 @@

Execute and document benchmarks reproducibly.

{% for (const p of it.projects) { %}
{%= p.name %}
+ href="/{%= p.namespacename %}/{%= p.slug %}/data">{%= p.name %}
{% if (p.showchanges) { %}
Changes
@@ -50,7 +51,7 @@
Changes
if (p.allresults) { %}
{% } %} - Timeline + Timeline
{% } diff --git a/src/backend/project/project-data.html b/src/backend/project/project-data.html index 4905e0f6..7ef8a35b 100644 --- a/src/backend/project/project-data.html +++ b/src/backend/project/project-data.html @@ -4,6 +4,7 @@ + ReBench: {%= it.project.name %} {%- include('header.html', { rebenchVersion: it.rebenchVersion }) %} diff --git a/src/backend/project/project.html b/src/backend/project/project.html index 59be1cb6..5b68d556 100644 --- a/src/backend/project/project.html +++ b/src/backend/project/project.html @@ -35,13 +35,14 @@

{%= it.description%}

{%= it.name %}
+ href="/{%= it.namespacename %}/{%= it.slug %}/data">{%= it.name %}
{% if (it.showchanges) { %}
Changes
@@ -55,7 +56,7 @@
Changes
{% } %}
- Timeline + Timeline
diff --git a/src/frontend/project-data.ts b/src/frontend/project-data.ts index 64699dc6..397202f2 100644 --- a/src/frontend/project-data.ts +++ b/src/frontend/project-data.ts @@ -3,6 +3,7 @@ import { renderProjectDataOverview } from './render.js'; const projectId = $('#project-id').attr('value'); const projectSlug = $('#project-slug').attr('value'); +const namespaceSlug = $('#namespace-slug').attr('value'); const dataOverviewP = apiFetch('/rebenchdb/dash/:projectId/data-overview', { projectId }); @@ -10,5 +11,5 @@ const dataOverviewP = apiFetch('/rebenchdb/dash/:projectId/data-overview', { $(async () => { const dataOverviewResponse = await dataOverviewP; const data = dataOverviewResponse.data; - renderProjectDataOverview(data, projectSlug); + renderProjectDataOverview(data, namespaceSlug, projectSlug); }); diff --git a/src/frontend/render.ts b/src/frontend/render.ts index c21a7c2a..93d4de6d 100644 --- a/src/frontend/render.ts +++ b/src/frontend/render.ts @@ -59,10 +59,11 @@ function formatCommitMessages(messages) { export function renderProjectDataOverview( data: any[], + namespaceSlug: string, projectSlug: string ): void { const tBody = $('#data-overview'); - const pSlug = projectSlug; + const dataUrl = `/${namespaceSlug}/${projectSlug}/data`; let hasDesc = false; @@ -89,8 +90,8 @@ export function renderProjectDataOverview( ${row.measurements} ${row.expid} - JSON, - CSV + JSON, + CSV `); tBody.find('a[href="#"]').on('click', expandMessage); @@ -137,6 +138,7 @@ function setHref(event, projectId: string, isBaseline: boolean) { // every time a commit is clicked, check to see if both left and right // commit are defined. set link if that is true const baseJQ = $(`#p${projectId}-baseline`); + const namespaceSlug = baseJQ.data('namespace-slug'); const projectSlug = baseJQ.data('project-slug'); const clicked = $(event.currentTarget).data('hash'); @@ -157,7 +159,7 @@ function setHref(event, projectId: string, isBaseline: boolean) { $(`#p${projectId}-compare`).attr( 'href', - `/${projectSlug}/compare/${baseline}..${change}` + `/${namespaceSlug}/${projectSlug}/compare/${baseline}..${change}` ); } diff --git a/tests/data/expected-results/main/index.html b/tests/data/expected-results/main/index.html index fb97bf84..54ddf450 100644 --- a/tests/data/expected-results/main/index.html +++ b/tests/data/expected-results/main/index.html @@ -46,13 +46,14 @@

Execute and document benchmarks reproducibly.

Small Example Project
+href="/legacy/Small-Example-Project/data">Small Example Project
Changes
@@ -61,7 +62,7 @@
Changes
Compare -Timeline +Timeline
diff --git a/tests/data/expected-results/project/project-data.html b/tests/data/expected-results/project/project-data.html index df2ca261..5fca5945 100644 --- a/tests/data/expected-results/project/project-data.html +++ b/tests/data/expected-results/project/project-data.html @@ -4,6 +4,7 @@ + ReBench: Test Project From 29698b677dd782f2959e785a4fea805588c5640c Mon Sep 17 00:00:00 2001 From: benjaminbucan Date: Tue, 10 Nov 2026 18:26:44 +0100 Subject: [PATCH 11/12] Remove unused redirect --- src/backend/project/project.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/backend/project/project.ts b/src/backend/project/project.ts index c7c0befc..bee4dda4 100644 --- a/src/backend/project/project.ts +++ b/src/backend/project/project.ts @@ -17,11 +17,6 @@ import { } from '../../backend/util.js'; import { Source } from '../db/types.js'; -/** @deprecated This is support for urls without the namespace slug. */ -export function redirectToLegacyProjectPage(ctx: ParameterizedContext): void { - ctx.redirect(`/${legacyGroupName}/${ctx.params.projectSlug}`); -} - /** Supports URLs that predate namespaces. */ export function redirectToLegacyNamespace(ctx: ParameterizedContext): void { ctx.redirect(`/${legacyGroupName}${ctx.url}`); From 4570d8a4f01b5efb995ac0912bbe9a7e1bac6c1e Mon Sep 17 00:00:00 2001 From: benjaminbucan Date: Tue, 10 Nov 2026 18:34:58 +0100 Subject: [PATCH 12/12] Merge Project and ProjectWithNamespace to always include the namespace --- src/backend/db/db.ts | 75 ++++++++++++++++----------- src/backend/db/types.ts | 3 -- src/backend/github/github.ts | 5 +- tests/backend/project/project.test.ts | 4 +- 4 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/backend/db/db.ts b/src/backend/db/db.ts index 17e48447..c8f31fbd 100644 --- a/src/backend/db/db.ts +++ b/src/backend/db/db.ts @@ -28,7 +28,6 @@ import type { MeasurementData, Metadata, Project, - ProjectWithNamespace, RevisionComparison, RevisionData, Run, @@ -76,6 +75,11 @@ const measurementDataTableJoins = ` JOIN Criterion ON criterion = criterion.id JOIN Run ON runId = run.id`; +const selectProjectWithNamespace = ` + SELECT p.*, n.name AS namespacename + FROM Project p + JOIN Namespace n ON p.namespaceId = n.id`; + function filterCommitMessage(msg) { return msg .replaceAll('\\n', '\n') // resolve new lines @@ -97,7 +101,6 @@ export abstract class Database { protected readonly timelineUpdater: BatchingTimelineUpdater | null; private readonly queries = { - fetchProjectByName: 'SELECT * FROM Project WHERE name = $1', insertMeasurementBatchedN: 'GENERATED' }; @@ -484,35 +487,44 @@ export abstract class Database { }); } - public async recordProject(projectName: string): Promise { - return this.recordCached(this.projects, projectName, { - name: 'insertOrFetchProjectByName', - text: `WITH insertedRow AS ( + public async recordProject( + namespaceName: string, + projectName: string + ): Promise { + const cacheKey = `${namespaceName}/${projectName}`; + return this.recordCached(this.projects, cacheKey, { + name: 'insertOrFetchProjectByNamespaceAndName', + text: `WITH ns AS ( + SELECT id, name FROM Namespace WHERE name = $3 + ), insertedRow AS ( INSERT INTO Project (name, slug, namespaceId) SELECT $1, regexp_replace($2, '[^0-9a-zA-Z-]', '-', 'g'), - n.id - FROM Namespace n - WHERE n.name = $3 + ns.id + FROM ns ON CONFLICT DO NOTHING RETURNING * + ), foundRow AS ( + SELECT * FROM insertedRow + UNION ALL + SELECT p.* + FROM Project p + JOIN ns ON p.namespaceId = ns.id + WHERE p.name = $1 ) - SELECT * FROM insertedRow - UNION ALL - SELECT * FROM Project WHERE name = $1;`, - values: [projectName, projectName, legacyGroupName] + SELECT foundRow.*, ns.name AS namespacename + FROM foundRow, ns;`, + values: [projectName, projectName, namespaceName] }); } public async getProjectBySlugs( namespaceSlug: string, projectSlug: string - ): Promise { + ): Promise { const result = await this.query({ name: 'fetchProjectByNamespaceAndSlug', - text: `SELECT p.*, n.name AS namespacename - FROM Project p - JOIN Namespace n ON p.namespaceId = n.id + text: `${selectProjectWithNamespace} WHERE lower(n.name) = lower($1) AND lower(p.slug) = lower($2)`, values: [namespaceSlug, projectSlug] @@ -527,7 +539,7 @@ export abstract class Database { public async getProjectByExpId(expId: number): Promise { const q = { name: 'fetchProjectByExpId', - text: `SELECT p.* FROM Project p + text: `${selectProjectWithNamespace} JOIN Experiment e ON e.projectId = p.id WHERE e.id = $1`, values: [expId] @@ -541,20 +553,23 @@ export abstract class Database { return result.rows[0]; } - public async getProjectByName(projectName: string): Promise { - return >this.getCached(this.projects, projectName, { - name: 'fetchProjectByName', - text: this.queries.fetchProjectByName, - values: [projectName] + public async getProjectByName( + namespaceName: string, + projectName: string + ): Promise { + const cacheKey = `${namespaceName}/${projectName}`; + return >this.getCached(this.projects, cacheKey, { + name: 'fetchProjectByNamespaceAndName', + text: `${selectProjectWithNamespace} + WHERE n.name = $1 AND p.name = $2`, + values: [namespaceName, projectName] }); } - public async getAllProjects(): Promise { + public async getAllProjects(): Promise { const result = await this.query({ name: 'fetchAllProjects', - text: `SELECT p.*, n.name AS namespacename - FROM Project p - JOIN Namespace n ON p.namespaceId = n.id + text: `${selectProjectWithNamespace} ORDER BY p.position DESC` }); return result.rows; @@ -563,7 +578,8 @@ export abstract class Database { public async getProject(projectId: number): Promise { const result = await this.query({ name: 'fetchProjectById', - text: 'SELECT * FROM Project WHERE id = $1', + text: `${selectProjectWithNamespace} + WHERE p.id = $1`, values: [projectId] }); @@ -667,7 +683,8 @@ export abstract class Database { return this.exps.get(cacheKey); } - const project = await this.recordProject(data.projectName); + // TODO: use the namespace sent by ReBench + const project = await this.recordProject(legacyGroupName, data.projectName); return this.recordCached(this.exps, cacheKey, { name: 'insertOrFetchExperimentByProjectIdAndName', diff --git a/src/backend/db/types.ts b/src/backend/db/types.ts index d7a4452d..fec63aca 100644 --- a/src/backend/db/types.ts +++ b/src/backend/db/types.ts @@ -73,9 +73,6 @@ export interface Project { githubnotification: boolean; basebranch: string; namespaceid: number; -} - -export interface ProjectWithNamespace extends Project { namespacename: string; } diff --git a/src/backend/github/github.ts b/src/backend/github/github.ts index 48bb7efd..37bfef76 100644 --- a/src/backend/github/github.ts +++ b/src/backend/github/github.ts @@ -8,7 +8,7 @@ import { createAppAuth } from '@octokit/auth-app'; import { existsSync, readFileSync } from 'fs'; import { log } from '../logging.js'; import { BenchmarkCompletion } from '../../shared/api.js'; -import { dbConfig, siteConfig } from '../util.js'; +import { dbConfig, legacyGroupName, siteConfig } from '../util.js'; import { getSummaryPlotFileName, renderCompare } from '../compare/report.js'; export async function handleReBenchCompletion( @@ -50,7 +50,8 @@ async function reportCompletion( ): Promise { await db.reportCompletion(data); - const project = await db.getProjectByName(data.projectName); + // TODO: use the namespace sent by ReBench + const project = await db.getProjectByName(legacyGroupName, data.projectName); if (!project) { throw new Error(`No project with name ${data.projectName} found.`); } diff --git a/tests/backend/project/project.test.ts b/tests/backend/project/project.test.ts index 7ed58f90..876ec620 100644 --- a/tests/backend/project/project.test.ts +++ b/tests/backend/project/project.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from '@jest/globals'; import { initJestMatchers } from '../../helpers.js'; -import { ProjectWithNamespace } from '../../../src/backend/db/types.js'; +import { Project } from '../../../src/backend/db/types.js'; import { prepareTemplate } from '../../../src/backend/templates.js'; import { robustPath } from '../../../src/backend/util.js'; @@ -8,7 +8,7 @@ initJestMatchers(); describe('renderProjectDataPage', () => { it('should render the page', () => { - const project: ProjectWithNamespace = { + const project: Project = { id: 1, name: 'Test Project', slug: 'test-project',