mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-03 07:10:46 +08:00
chore(server): fix connection
This commit is contained in:
+24
-18
@@ -39,30 +39,36 @@ export class MigrateLegacyContextBlobArtifacts1786820000000 {
|
||||
|
||||
const runtime = injector.get(BackendRuntimeProvider, { strict: false });
|
||||
const blobs = await db.$queryRaw<LegacyContextBlob[]>`
|
||||
SELECT DISTINCT
|
||||
session.workspace_id AS "workspaceId",
|
||||
WITH referenced_blobs AS (
|
||||
SELECT DISTINCT
|
||||
session.workspace_id,
|
||||
value #>> '{}' AS blob_key
|
||||
FROM ai_contexts context
|
||||
JOIN ai_sessions_metadata session ON session.id = context.session_id
|
||||
CROSS JOIN LATERAL jsonb_path_query(
|
||||
context.config::jsonb,
|
||||
'$.** ? (@.type() == "string")'
|
||||
) AS referenced_value(value)
|
||||
)
|
||||
SELECT
|
||||
referenced.workspace_id AS "workspaceId",
|
||||
blob.key AS "blobId",
|
||||
blob.mime AS "mimeType"
|
||||
FROM ai_contexts context
|
||||
JOIN ai_sessions_metadata session ON session.id = context.session_id
|
||||
FROM referenced_blobs referenced
|
||||
JOIN blobs blob
|
||||
ON blob.workspace_id = session.workspace_id
|
||||
ON blob.workspace_id = referenced.workspace_id
|
||||
AND blob.key = referenced.blob_key
|
||||
AND blob.deleted_at IS NULL
|
||||
AND blob.status = 'completed'
|
||||
WHERE jsonb_path_exists(
|
||||
context.config::jsonb,
|
||||
'$.** ? (@ == $blobKey)',
|
||||
jsonb_build_object('blobKey', to_jsonb(blob.key::text))
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM workspace_artifacts artifact
|
||||
WHERE artifact.workspace_id = referenced.workspace_id
|
||||
AND artifact.storage_scope = 'blob'
|
||||
AND artifact.storage_key = concat(referenced.workspace_id, '/', blob.key)
|
||||
AND artifact.status = 'ready'
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM workspace_artifacts artifact
|
||||
WHERE artifact.workspace_id = session.workspace_id
|
||||
AND artifact.storage_scope = 'blob'
|
||||
AND artifact.storage_key = concat(session.workspace_id, '/', blob.key)
|
||||
AND artifact.status = 'ready'
|
||||
)
|
||||
ORDER BY session.workspace_id, blob.key
|
||||
ORDER BY referenced.workspace_id, blob.key
|
||||
`;
|
||||
|
||||
for (const blob of blobs) {
|
||||
|
||||
@@ -42,7 +42,9 @@ export async function run() {
|
||||
const url = app.get(URLHelper);
|
||||
let telemetry: TelemetryService | null = null;
|
||||
try {
|
||||
telemetry = app.get(TelemetryService, { strict: false });
|
||||
if (env.role !== ServerRole.Worker) {
|
||||
telemetry = app.get(TelemetryService, { strict: false });
|
||||
}
|
||||
} catch {
|
||||
telemetry = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user