Skip to content

fix: preserve table ordering from database in category responses#1616

Merged
Artuomka merged 1 commit into
mainfrom
backend_table_categories_sorting_fix
Feb 19, 2026
Merged

fix: preserve table ordering from database in category responses#1616
Artuomka merged 1 commit into
mainfrom
backend_table_categories_sorting_fix

Conversation

@Artuomka

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings February 19, 2026 15:33
@Artuomka Artuomka enabled auto-merge February 19, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the table-categories “v2” response construction so that tables within each category are returned in the same order as stored in the database (instead of the order from the global tablesRO list).

Changes:

  • Build each category’s tables list by iterating category.tables and matching each name to its corresponding tablesRO entry.
  • Filter out category table names that don’t exist (or are hidden) by dropping unmatched lookups.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const tablesInCategory = tablesRO.filter((tableRO) => {
return category.tables.includes(tableRO.table);
});
const tablesInCategory = category.tables

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

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

This changes behavior when category.tables contains duplicates: the previous filter(...includes...) could only include each tablesRO entry once, but the new map(...find...) will repeat duplicates, returning the same table multiple times in the response. Consider de-duplicating category.tables (while preserving order) and/or enforcing uniqueness in table-category validation so API responses stay consistent.

Suggested change
const tablesInCategory = category.tables
const uniqueTableNames = Array.from(new Set(category.tables));
const tablesInCategory = uniqueTableNames

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +108
const tablesInCategory = category.tables
.map((tableName) => tablesRO.find((tableRO) => tableRO.table === tableName))
.filter(Boolean);

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

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

category.tables.map(...tablesRO.find(...)) performs a linear search in tablesRO for every table name (O(categoryTables * tablesRO)). For connections with many tables/categories this can add noticeable overhead; consider building a lookup map (e.g., name -> tableRO) once and then doing O(1) lookups while preserving the category.tables order.

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +108
const tablesInCategory = category.tables
.map((tableName) => tablesRO.find((tableRO) => tableRO.table === tableName))
.filter(Boolean);

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

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

This logic is intended to preserve the DB-stored ordering of category.tables, but there’s no test asserting the returned table order within a category. Please add/update coverage (likely in the existing /table-categories/v2/:connectionId e2e test) to verify that when a category is saved with an explicit tables order, the response returns tables in that same order.

Copilot uses AI. Check for mistakes.
@Artuomka Artuomka merged commit d818322 into main Feb 19, 2026
23 of 25 checks passed
@Artuomka Artuomka deleted the backend_table_categories_sorting_fix branch February 19, 2026 15:47
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.

2 participants