chore(orchestration): remote joiner query planner (#13364)

What:
 - Added query planning to the Remote Joiner, enabling phased and parallel execution of data aggregation.
- Replaced object deletes with non-enumerable property hiding to improve performance.
This commit is contained in:
Carlos R. L. Rodrigues
2025-09-04 14:18:02 +00:00
committed by GitHub
parent b7fef5b7ef
commit bd571aca82
16 changed files with 1234 additions and 191 deletions
@@ -0,0 +1,26 @@
const { defineConfig } = require("@medusajs/framework/utils")
const DB_HOST = process.env.DB_HOST
const DB_USERNAME = process.env.DB_USERNAME
const DB_PASSWORD = process.env.DB_PASSWORD
const DB_NAME = process.env.DB_TEMP_NAME
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
process.env.DATABASE_URL = DB_URL
module.exports = defineConfig({
admin: {
disable: true,
},
projectConfig: {
http: {
jwtSecret: "secret",
},
},
modules: [
{
key: "translation",
resolve: "./src/modules/translation",
},
],
})
@@ -0,0 +1,8 @@
import ProductModule from "@medusajs/medusa/product"
import { defineLink } from "@medusajs/utils"
import Translation from "../modules/translation"
export default defineLink(
ProductModule.linkable.productOption.id,
Translation.linkable.translation.id
)
@@ -0,0 +1,8 @@
import ProductModule from "@medusajs/medusa/product"
import { defineLink } from "@medusajs/utils"
import Translation from "../modules/translation"
export default defineLink(
ProductModule.linkable.productCategory.id,
Translation.linkable.translation.id
)
@@ -0,0 +1,8 @@
import { defineLink } from "@medusajs/framework/utils"
import ProductModule from "@medusajs/medusa/product"
import Translation from "../modules/translation"
export default defineLink(
ProductModule.linkable.product.id,
Translation.linkable.translation.id
)
@@ -0,0 +1,8 @@
import ProductModule from "@medusajs/medusa/product"
import { defineLink } from "@medusajs/utils"
import Translation from "../modules/translation"
export default defineLink(
ProductModule.linkable.productVariant.id,
Translation.linkable.translation.id
)
@@ -0,0 +1,8 @@
import { Module } from "@medusajs/framework/utils";
import { TranslationModule } from "./service";
export const TRANSLATION = "translation";
export default Module(TRANSLATION, {
service: TranslationModule,
});
@@ -0,0 +1,95 @@
{
"namespaces": [
"public"
],
"name": "public",
"tables": [
{
"columns": {
"id": {
"name": "id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"key": {
"name": "key",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"value": {
"name": "value",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "'{}'",
"mappedType": "json"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 6,
"default": "now()",
"mappedType": "datetime"
},
"updated_at": {
"name": "updated_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 6,
"default": "now()",
"mappedType": "datetime"
},
"deleted_at": {
"name": "deleted_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"length": 6,
"mappedType": "datetime"
}
},
"name": "translation",
"schema": "public",
"indexes": [
{
"keyName": "IDX_translation_key_unique",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_translation_key_unique\" ON \"translation\" (key) WHERE deleted_at IS NULL"
},
{
"keyName": "translation_pkey",
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
}
],
"checks": [],
"foreignKeys": {}
}
]
}
@@ -0,0 +1,14 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20240907134741 extends Migration {
async up(): Promise<void> {
this.addSql('create table if not exists "translation" ("id" text not null, "key" text not null, "value" jsonb not null default \'{}\', "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "translation_pkey" primary key ("id"));');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_translation_key_unique" ON "translation" (key) WHERE deleted_at IS NULL;');
}
async down(): Promise<void> {
this.addSql('drop table if exists "translation" cascade;');
}
}
@@ -0,0 +1 @@
export { default as Translation } from "./translation";
@@ -0,0 +1,7 @@
import { model } from "@medusajs/framework/utils";
export default model.define("translation", {
id: model.id({ prefix: "i18n" }).primaryKey(),
key: model.text().unique(),
value: model.json().default({}),
});
@@ -0,0 +1,49 @@
import { MedusaService } from "@medusajs/framework/utils"
import { Translation } from "./models"
export class TranslationModule extends MedusaService({
Translation,
}) {
private manager_
constructor({ manager }) {
super(...arguments)
this.manager_ = manager
}
// @ts-expect-error
async listTranslations(find, config, medusaContext) {
const { filters, context, id } = find ?? {}
let lang = null
if (filters || context) {
lang = filters?.lang ?? context?.lang
delete filters?.lang
}
const knex = this.manager_.getKnex()
const q = knex({ tr: "translation" }).select(["tr.id", "tr.key"])
// Select JSON content for a specific lang if provided
if (lang) {
q.select(
knex.raw("tr.value->? AS content", [lang]),
knex.raw("? AS lang", [lang])
)
} else {
q.select("tr.value")
}
const key = filters?.key
if (id) {
q.whereIn("tr.id", Array.isArray(id) ? id : [id])
} else if (key) {
q.whereIn("tr.key", Array.isArray(key) ? key : [key])
}
// console.log(q.toString())
return await q
}
}