Fix sync-all: use subquery for PostgreSQL-compatible UPDATE LIMIT

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-23 23:35:04 +03:00
parent 36a1f26ca7
commit 59ea0eb9c2

View File

@@ -391,19 +391,24 @@ class GiteaService {
try { try {
const sha = await this.commitEndpointFiles(ep, cfg.prod_branch || 'main', `Sync: ${ep.name}`); const sha = await this.commitEndpointFiles(ep, cfg.prod_branch || 'main', `Sync: ${ep.name}`);
// Mark published version as synced // Mark published version as synced
if (sha && ep.published_version_id) { if (sha) {
await mainPool.query( const versionId = ep.published_version_id;
'UPDATE endpoint_versions SET gitea_commit_sha = $1 WHERE id = $2', if (versionId) {
[sha, ep.published_version_id] await mainPool.query(
); 'UPDATE endpoint_versions SET gitea_commit_sha = $1 WHERE id = $2',
} else if (sha) { [sha, versionId]
// No published version yet — mark the latest version );
await mainPool.query( } else {
`UPDATE endpoint_versions SET gitea_commit_sha = $1 await mainPool.query(
WHERE endpoint_id = $2 AND gitea_commit_sha IS NULL `UPDATE endpoint_versions SET gitea_commit_sha = $1
ORDER BY version_number DESC LIMIT 1`, WHERE id = (
[sha, ep.id] SELECT id FROM endpoint_versions
); WHERE endpoint_id = $2
ORDER BY version_number DESC LIMIT 1
)`,
[sha, ep.id]
);
}
} }
synced++; synced++;
} catch (err: any) { } catch (err: any) {