feat(server): improve calendar sync queue (#14783)

This commit is contained in:
DarkSky
2026-04-05 11:05:35 +08:00
parent 46e7e35357
commit 43704d60fb
5 changed files with 339 additions and 133 deletions
@@ -6,6 +6,7 @@ import { AppModule } from '../app.module';
import {
CANARY_CLIENT_VERSION_MAX_AGE_DAYS,
ConfigFactory,
hasNewerVersion,
UseNamedGuard,
} from '../base';
import { Public } from '../core/auth/guard';
@@ -249,3 +250,11 @@ test('should reject old canary date version in canary namespace', async t => {
env.NAMESPACE = prevNamespace;
}
});
test('should compare release versions for available upgrades', t => {
t.false(hasNewerVersion('0.26.5', '0.26.4'));
t.false(hasNewerVersion('0.26.5', '0.26.5'));
t.true(hasNewerVersion('0.26.5', '0.26.6'));
t.true(hasNewerVersion('0.26.5', '0.26.6-beta.1'));
t.false(hasNewerVersion('0.26.6-beta.2', '0.26.6-beta.1'));
});
@@ -1,3 +1,5 @@
import semver from 'semver';
const DAY_MS = 24 * 60 * 60 * 1000;
// Example: 2026.2.6-canary.015
@@ -89,3 +91,26 @@ export function checkCanaryDateClientVersion(
normalized: parsed.normalized,
};
}
function normalizeComparableVersion(version: string): string | null {
const canary = parseCanaryDateClientVersion(version);
return semver.valid(canary?.normalized ?? version.trim(), {
loose: true,
});
}
export function hasNewerVersion(
currentVersion: string,
nextVersion: string
): boolean {
const current = normalizeComparableVersion(currentVersion);
const next = normalizeComparableVersion(nextVersion);
if (!current || !next) {
return currentVersion.trim() !== nextVersion.trim();
}
return semver.gt(next, current, {
loose: true,
});
}
@@ -12,7 +12,7 @@ import {
} from '@nestjs/graphql';
import { GraphQLJSON, GraphQLJSONObject } from 'graphql-scalars';
import { Config, URLHelper } from '../../base';
import { Config, hasNewerVersion, URLHelper } from '../../base';
import { Namespace } from '../../env';
import { Feature, type WorkspaceFeatureName } from '../../models';
import { CurrentUser, Public } from '../auth';
@@ -143,7 +143,7 @@ export class ServerConfigResolver {
}>;
const latest = releases.at(0);
if (!latest || latest.name === env.version) {
if (!latest || !hasNewerVersion(env.version, latest.name)) {
return null;
}