-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix cloudflare build #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cloudflare build #360
Changes from 3 commits
69531b2
c07c69e
0358be9
242ed1f
eadeb39
f352d8f
10bd441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,12 +42,20 @@ import { | |
| */ | ||
| export class PostgresStorage implements IStorage { | ||
| private db: DatabaseAdapter; | ||
| private schemaReady: Promise<void>; | ||
| private _schemaReady: Promise<void> | null = null; | ||
| private get schemaReady(): Promise<void> { | ||
| if (!this._schemaReady) { | ||
| this._schemaReady = this.ensureMangaShelfColumns().catch((err) => { | ||
| this._schemaReady = null; | ||
| throw err; | ||
| }); | ||
| } | ||
| return this._schemaReady; | ||
| } | ||
|
Comment on lines
+46
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 由于 |
||
| public adapter: any; // 用于兼容 | ||
|
|
||
| constructor(adapter: DatabaseAdapter) { | ||
| this.db = adapter; | ||
| this.schemaReady = this.ensureMangaShelfColumns(); | ||
| // 创建一个简单的适配器用于设备管理 | ||
| this.adapter = new PostgresRedisHashAdapter(adapter); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
由于
ensureMangaShelfColumns方法内部捕获了所有异常且未向上抛出,因此schemaReadygetter 中的.catch分支实际上永远不会被触发。如果数据库在首次请求时由于临时网络抖动或未就绪而导致列添加失败,_schemaReady仍会被缓存为一个已成功解析的 Promise。这会导致后续所有对漫画书架的访问都默认列已存在,从而引发持续的数据库错误,且无法自动重试。\n\n建议修改ensureMangaShelfColumns,使其在遇到非预期错误(如连接失败等非“列已存在”的错误)时向上抛出异常,以便 lazy getter 能够正确重置_schemaReady并在下一次请求时重试。