Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

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

liuyid9c2dc8dfb23
diff --git a/packages/backend/server/src/config/affine.ts b/packages/backend/server/src/config/affine.ts
index 74536d8d9f..42193c8fd5 100644
--- a/packages/backend/server/src/config/affine.ts
+++ b/packages/backend/server/src/config/affine.ts
@@ -11,8 +11,8 @@
// > Configurations merge order
// 1. load environment variables (`.env` if provided, and from system)
// 2. load `src/fundamentals/config/default.ts` for all default settings
-// 3. apply `./affine.env.ts` patches
-// 4. apply `./affine.ts` patches (this file)
+// 3. apply `./affine.ts` patches (this file)
+// 4. apply `./affine.env.ts` patches
//
//
// ###############################################################
diff --git a/packages/backend/server/src/core/doc/manager.ts b/packages/backend/server/src/core/doc/manager.ts
index 5034d81537..1fa7ffafc5 100644
--- a/packages/backend/server/src/core/doc/manager.ts
+++ b/packages/backend/server/src/core/doc/manager.ts
@@ -382,7 +382,7 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
// take it ease, we don't want to overload db and or cpu
// if we limit the taken number here,
// 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
diff --git a/packages/backend/server/src/core/workspaces/controller.ts b/packages/backend/server/src/core/workspaces/controller.ts
index e6528fb7ff..02dc651ba8 100644
--- a/packages/backend/server/src/core/workspaces/controller.ts
+++ b/packages/backend/server/src/core/workspaces/controller.ts
@@ -56,7 +56,7 @@ export class WorkspacesController {
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);
}
@@ -106,6 +106,7 @@ export class WorkspacesController {
}
res.setHeader('content-type', 'application/octet-stream');
+ res.setHeader('cache-control', 'no-cache');
res.send(update);
}
@@ -142,6 +143,7 @@ export class WorkspacesController {
if (history) {
res.setHeader('content-type', 'application/octet-stream');
+ res.setHeader('cache-control', 'public, max-age=2592000, immutable');
res.send(history.blob);
} else {
throw new NotFoundException('Doc history not found');
diff --git a/packages/backend/server/src/fundamentals/config/def.ts b/packages/backend/server/src/fundamentals/config/def.ts
index cdfa6155d1..c946c19b7b 100644
--- a/packages/backend/server/src/fundamentals/config/def.ts
+++ b/packages/backend/server/src/fundamentals/config/def.ts
@@ -315,6 +315,12 @@ export interface AFFiNEConfig {
*/
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.
*
diff --git a/packages/backend/server/src/fundamentals/config/default.ts b/packages/backend/server/src/fundamentals/config/default.ts
index f7712629f0..d88312d1b1 100644
--- a/packages/backend/server/src/fundamentals/config/default.ts
+++ b/packages/backend/server/src/fundamentals/config/default.ts
@@ -184,6 +184,7 @@ export const getDefaultAFFiNEConfig: () => AFFiNEConfig = () => {
manager: {
enableUpdateAutoMerging: flavor !== 'sync',
updatePollInterval: 3000,
+ maxUpdatesPullCount: 500,
experimentalMergeWithYOcto: false,
},
history: {
diff --git a/packages/backend/server/src/plugins/payment/index.ts b/packages/backend/server/src/plugins/payment/index.ts
index 9c11f95563..0539b9fd90 100644
--- a/packages/backend/server/src/plugins/payment/index.ts
+++ b/packages/backend/server/src/plugins/payment/index.ts
@@ -23,6 +23,7 @@ import { StripeWebhook } from './webhook';
// 'plugins.payment.stripe.keys.webhookKey',
// ],
contributesTo: ServerFeature.Payment,
+ if: config => config.flavor.graphql,
})
export class PaymentModule {}
diff --git a/packages/backend/server/src/prelude.ts b/packages/backend/server/src/prelude.ts
index 095c768761..7f818774c7 100644
--- a/packages/backend/server/src/prelude.ts
+++ b/packages/backend/server/src/prelude.ts
@@ -44,18 +44,18 @@ async function load() {
// 3. load env => config map to `globalThis.AFFiNE.ENV_MAP
await loadRemote(AFFiNE_CONFIG_PATH, 'affine.env.js');
- // 4. apply `process.env` map overriding to `globalThis.AFFiNE`
- applyEnvToConfig(globalThis.AFFiNE);
-
- // 5. load `config/affine` to patch custom configs
+ // 4. load `config/affine` to patch custom configs
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]
if (!AFFiNE.isSelfhosted) {
await loadRemote(AFFiNE_CONFIG_PATH, 'affine.self.js');
}
+ // 6. apply `process.env` map overriding to `globalThis.AFFiNE`
+ applyEnvToConfig(globalThis.AFFiNE);
+
if (AFFiNE.node.dev) {
console.log(
'AFFiNE Config:',