fix(server): apply env overrides after all config merged (#5795)

This commit is contained in:
liuyi
2024-02-04 06:38:31 +00:00
parent 899528dcfd
commit d9c2dc8dfb
7 changed files with 19 additions and 9 deletions

View File

@@ -11,8 +11,8 @@
// > Configurations merge order // > Configurations merge order
// 1. load environment variables (`.env` if provided, and from system) // 1. load environment variables (`.env` if provided, and from system)
// 2. load `src/fundamentals/config/default.ts` for all default settings // 2. load `src/fundamentals/config/default.ts` for all default settings
// 3. apply `./affine.env.ts` patches // 3. apply `./affine.ts` patches (this file)
// 4. apply `./affine.ts` patches (this file) // 4. apply `./affine.env.ts` patches
// //
// //
// ############################################################### // ###############################################################

View File

@@ -382,7 +382,7 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
// take it ease, we don't want to overload db and or cpu // take it ease, we don't want to overload db and or cpu
// if we limit the taken number here, // if we limit the taken number here,
// user will never see the latest doc if there are too many updates pending to be merged. // user will never see the latest doc if there are too many updates pending to be merged.
take: 100, take: this.config.doc.manager.maxUpdatesPullCount,
}); });
// perf(memory): avoid sorting in db // perf(memory): avoid sorting in db

View File

@@ -56,7 +56,7 @@ export class WorkspacesController {
this.logger.warn(`Blob ${workspaceId}/${name} has no metadata`); this.logger.warn(`Blob ${workspaceId}/${name} has no metadata`);
} }
res.setHeader('cache-control', 'public, max-age=31536000, immutable'); res.setHeader('cache-control', 'public, max-age=2592000, immutable');
body.pipe(res); body.pipe(res);
} }
@@ -106,6 +106,7 @@ export class WorkspacesController {
} }
res.setHeader('content-type', 'application/octet-stream'); res.setHeader('content-type', 'application/octet-stream');
res.setHeader('cache-control', 'no-cache');
res.send(update); res.send(update);
} }
@@ -142,6 +143,7 @@ export class WorkspacesController {
if (history) { if (history) {
res.setHeader('content-type', 'application/octet-stream'); res.setHeader('content-type', 'application/octet-stream');
res.setHeader('cache-control', 'public, max-age=2592000, immutable');
res.send(history.blob); res.send(history.blob);
} else { } else {
throw new NotFoundException('Doc history not found'); throw new NotFoundException('Doc history not found');

View File

@@ -315,6 +315,12 @@ export interface AFFiNEConfig {
*/ */
updatePollInterval: number; updatePollInterval: number;
/**
* The maximum number of updates that will be pulled from the server at once.
* Existing for avoiding the server to be overloaded when there are too many updates for one doc.
*/
maxUpdatesPullCount: number;
/** /**
* Use `y-octo` to merge updates at the same time when merging using Yjs. * Use `y-octo` to merge updates at the same time when merging using Yjs.
* *

View File

@@ -184,6 +184,7 @@ export const getDefaultAFFiNEConfig: () => AFFiNEConfig = () => {
manager: { manager: {
enableUpdateAutoMerging: flavor !== 'sync', enableUpdateAutoMerging: flavor !== 'sync',
updatePollInterval: 3000, updatePollInterval: 3000,
maxUpdatesPullCount: 500,
experimentalMergeWithYOcto: false, experimentalMergeWithYOcto: false,
}, },
history: { history: {

View File

@@ -23,6 +23,7 @@ import { StripeWebhook } from './webhook';
// 'plugins.payment.stripe.keys.webhookKey', // 'plugins.payment.stripe.keys.webhookKey',
// ], // ],
contributesTo: ServerFeature.Payment, contributesTo: ServerFeature.Payment,
if: config => config.flavor.graphql,
}) })
export class PaymentModule {} export class PaymentModule {}

View File

@@ -44,18 +44,18 @@ async function load() {
// 3. load env => config map to `globalThis.AFFiNE.ENV_MAP // 3. load env => config map to `globalThis.AFFiNE.ENV_MAP
await loadRemote(AFFiNE_CONFIG_PATH, 'affine.env.js'); await loadRemote(AFFiNE_CONFIG_PATH, 'affine.env.js');
// 4. apply `process.env` map overriding to `globalThis.AFFiNE` // 4. load `config/affine` to patch custom configs
applyEnvToConfig(globalThis.AFFiNE);
// 5. load `config/affine` to patch custom configs
await loadRemote(AFFiNE_CONFIG_PATH, 'affine.js'); await loadRemote(AFFiNE_CONFIG_PATH, 'affine.js');
// 6. load `config/affine.self` to patch custom configs // 5. load `config/affine.self` to patch custom configs
// This is the file only take effect in [AFFiNE Cloud] // This is the file only take effect in [AFFiNE Cloud]
if (!AFFiNE.isSelfhosted) { if (!AFFiNE.isSelfhosted) {
await loadRemote(AFFiNE_CONFIG_PATH, 'affine.self.js'); await loadRemote(AFFiNE_CONFIG_PATH, 'affine.self.js');
} }
// 6. apply `process.env` map overriding to `globalThis.AFFiNE`
applyEnvToConfig(globalThis.AFFiNE);
if (AFFiNE.node.dev) { if (AFFiNE.node.dev) {
console.log( console.log(
'AFFiNE Config:', 'AFFiNE Config:',