@nxtedition/nxt-undici 7.3.5 → 7.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/interceptor/log.js +20 -0
- package/lib/sqlite-cache-store.js +8 -8
- package/package.json +1 -1
package/lib/interceptor/log.js
CHANGED
|
@@ -19,6 +19,9 @@ class Handler extends DecoratorHandler {
|
|
|
19
19
|
#statusCode
|
|
20
20
|
#headers
|
|
21
21
|
|
|
22
|
+
#globalIndex = -1
|
|
23
|
+
#globalArray = (globalThis.__undici_requests ??= [])
|
|
24
|
+
|
|
22
25
|
constructor(logOpts, opts, { handler }) {
|
|
23
26
|
super(handler)
|
|
24
27
|
|
|
@@ -31,6 +34,8 @@ class Handler extends DecoratorHandler {
|
|
|
31
34
|
|
|
32
35
|
this.#logger.debug('upstream request started')
|
|
33
36
|
this.#timing.created = this.#created + performance.timeOrigin
|
|
37
|
+
|
|
38
|
+
this.#globalIndex = this.#globalArray.push(this) - 1
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
onConnect(abort) {
|
|
@@ -110,6 +115,8 @@ class Handler extends DecoratorHandler {
|
|
|
110
115
|
this.#logger.debug(data, 'upstream request completed')
|
|
111
116
|
}
|
|
112
117
|
|
|
118
|
+
this.onDone()
|
|
119
|
+
|
|
113
120
|
super.onComplete()
|
|
114
121
|
}
|
|
115
122
|
|
|
@@ -137,8 +144,21 @@ class Handler extends DecoratorHandler {
|
|
|
137
144
|
this.#logger.error(data, 'upstream request failed')
|
|
138
145
|
}
|
|
139
146
|
|
|
147
|
+
this.onDone()
|
|
148
|
+
|
|
140
149
|
super.onError(err)
|
|
141
150
|
}
|
|
151
|
+
|
|
152
|
+
onDone() {
|
|
153
|
+
if (this.#globalIndex !== -1) {
|
|
154
|
+
const tmp = this.#globalArray.pop()
|
|
155
|
+
if (tmp !== this) {
|
|
156
|
+
this.#globalArray[this.#globalIndex] = tmp
|
|
157
|
+
tmp.#globalIndex = this.#globalIndex
|
|
158
|
+
}
|
|
159
|
+
this.#globalIndex = -1
|
|
160
|
+
}
|
|
161
|
+
}
|
|
142
162
|
}
|
|
143
163
|
|
|
144
164
|
export default (logOpts) => (dispatch) => (opts, handler) =>
|
|
@@ -73,10 +73,14 @@ export class SqliteCacheStore {
|
|
|
73
73
|
constructor(opts) {
|
|
74
74
|
this.#db = new DatabaseSync(opts?.location ?? ':memory:', { timeout: 40, ...opts?.db })
|
|
75
75
|
|
|
76
|
+
const maxSize = opts?.maxSize ?? 256 * 1024 * 1024
|
|
76
77
|
this.#db.exec(`
|
|
77
78
|
PRAGMA journal_mode = WAL;
|
|
78
|
-
PRAGMA synchronous =
|
|
79
|
-
PRAGMA
|
|
79
|
+
PRAGMA synchronous = OFF;
|
|
80
|
+
PRAGMA wal_autocheckpoint = 10000;
|
|
81
|
+
PRAGMA cache_size = -${Math.ceil(maxSize / 1024 / 8)};
|
|
82
|
+
PRAGMA mmap_size = ${maxSize};
|
|
83
|
+
PRAGMA max_page_count = ${Math.ceil(maxSize / 4096)};
|
|
80
84
|
PRAGMA optimize;
|
|
81
85
|
|
|
82
86
|
CREATE TABLE IF NOT EXISTS cacheInterceptorV${VERSION} (
|
|
@@ -101,12 +105,6 @@ export class SqliteCacheStore {
|
|
|
101
105
|
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${VERSION}_deleteExpiredValuesQuery ON cacheInterceptorV${VERSION}(deleteAt);
|
|
102
106
|
`)
|
|
103
107
|
|
|
104
|
-
const maxSize = opts?.maxSize ?? 256 * 1024 * 1024
|
|
105
|
-
{
|
|
106
|
-
const { page_size: pageSize } = this.#db.prepare('PRAGMA page_size').get()
|
|
107
|
-
this.#db.exec(`PRAGMA max_page_count = ${Math.ceil(maxSize / pageSize)}`)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
108
|
this.#getValuesQuery = this.#db.prepare(`
|
|
111
109
|
SELECT
|
|
112
110
|
id,
|
|
@@ -159,6 +157,8 @@ export class SqliteCacheStore {
|
|
|
159
157
|
|
|
160
158
|
purgeStale() {
|
|
161
159
|
this.#prune()
|
|
160
|
+
this.#db.exec('PRAGMA wal_checkpoint(TRUNCATE)')
|
|
161
|
+
this.#db.exec('PRAGMA optimize')
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
close() {
|