dobo-extra 1.2.2 → 1.2.3
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/package.json +1 -1
- package/plugin-method/export-to.js +22 -1
package/package.json
CHANGED
|
@@ -36,11 +36,32 @@ async function getFile (dest, ensureDir) {
|
|
|
36
36
|
|
|
37
37
|
async function getData ({ source, filter, count, stream, progressFn, fields }) {
|
|
38
38
|
let cnt = count ?? 0
|
|
39
|
-
const {
|
|
39
|
+
const { find } = this.lib._
|
|
40
|
+
const { recordFind, getSchema } = this.app.dobo
|
|
41
|
+
const { maxLimit, hardLimit } = this.app.dobo.config.default.filter
|
|
42
|
+
filter.limit = maxLimit
|
|
43
|
+
let sort
|
|
44
|
+
const schema = getSchema(source)
|
|
45
|
+
const idField = find(schema.properties, { name: 'id' })
|
|
46
|
+
for (const name of ['createdAt', 'updatedAt', 'ts', 'dt']) {
|
|
47
|
+
const field = find(schema.properties, { name })
|
|
48
|
+
if (field) {
|
|
49
|
+
sort = field.name
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
filter.sort = `${sort ?? idField}:1`
|
|
40
54
|
for (;;) {
|
|
41
55
|
const batchStart = new Date()
|
|
42
56
|
const { data, page } = await recordFind(source, filter, { dataOnly: false, fields })
|
|
43
57
|
if (data.length === 0) break
|
|
58
|
+
if (cnt + data.length > hardLimit) {
|
|
59
|
+
const sliced = data.slice(0, hardLimit - cnt)
|
|
60
|
+
await stream.pull(sliced)
|
|
61
|
+
cnt += sliced.length
|
|
62
|
+
if (progressFn) await progressFn.call(this, { batchNo: page, data: sliced, batchStart, batchEnd: new Date() })
|
|
63
|
+
break
|
|
64
|
+
}
|
|
44
65
|
cnt += data.length
|
|
45
66
|
await stream.pull(data)
|
|
46
67
|
if (progressFn) await progressFn.call(this, { batchNo: page, data, batchStart, batchEnd: new Date() })
|