querysub 0.422.0 → 0.424.0
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
CHANGED
|
@@ -2,7 +2,7 @@ import { lazy } from "socket-function/src/caching";
|
|
|
2
2
|
import { Archives, nestArchives } from "../../../-a-archives/archives";
|
|
3
3
|
import { deepCloneJSON, keyByArray, nextId, sort, timeInHour, timeInMinute, timeInSecond, timeoutToUndefinedSilent } from "socket-function/src/misc";
|
|
4
4
|
import { BufferIndex } from "./BufferIndex";
|
|
5
|
-
import { delay, runInParallel, runInSerial, runInfinitePoll } from "socket-function/src/batching";
|
|
5
|
+
import { delay, runInParallel, runInSerial, runInfinitePoll, runInfinitePollCallAtStart } from "socket-function/src/batching";
|
|
6
6
|
import { IndexedLogResults, Reader, SearchParams, addReadToResults, createEmptyIndexedLogResults, INDEX_EXTENSION, mergeIndexedLogResults } from "./BufferIndexHelpers";
|
|
7
7
|
import { getDomain, isPublic } from "../../../config";
|
|
8
8
|
import { getArchivesHome, getArchivesLocal } from "../../../-a-archives/archivesDisk";
|
|
@@ -127,7 +127,7 @@ export class IndexedLogs<T> {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
private runLogMoverLoop = lazy(() => {
|
|
130
|
-
|
|
130
|
+
void runInfinitePollCallAtStart(timeInMinute * 5, async () => {
|
|
131
131
|
await this.moveLogsToPublic();
|
|
132
132
|
});
|
|
133
133
|
});
|
|
@@ -133,8 +133,37 @@ export async function moveLogsToPublic(config: {
|
|
|
133
133
|
|
|
134
134
|
let byStartTime = keyByArray(localPaths, x => x.startTime);
|
|
135
135
|
|
|
136
|
-
let
|
|
137
|
-
sort(
|
|
136
|
+
let initialGroups = Array.from(byStartTime.values());
|
|
137
|
+
sort(initialGroups, x => x[0].startTime);
|
|
138
|
+
|
|
139
|
+
// Get compressed file sizes for all paths in parallel to avoid loading too much data at once
|
|
140
|
+
let sizeThreshold = maxSingleFileData / 10;
|
|
141
|
+
let allPathsFlat = initialGroups.flat();
|
|
142
|
+
let pathSizes = await Promise.all(allPathsFlat.map(async path => {
|
|
143
|
+
let info = await localLogs.getInfo(path.fullPath);
|
|
144
|
+
return { path, size: info?.size || 0 };
|
|
145
|
+
}));
|
|
146
|
+
let sizeMap = new Map(pathSizes.map(x => [x.path, x.size]));
|
|
147
|
+
|
|
148
|
+
// Split individual groups if their compressed file sizes exceed threshold
|
|
149
|
+
// but keep groups separate (don't mix startTimes)
|
|
150
|
+
let groups: typeof initialGroups = [];
|
|
151
|
+
for (let group of initialGroups) {
|
|
152
|
+
let currentSize = 0;
|
|
153
|
+
|
|
154
|
+
for (let path of group) {
|
|
155
|
+
let size = sizeMap.get(path) || 0;
|
|
156
|
+
|
|
157
|
+
if (groups.length === 0 || currentSize + size > sizeThreshold) {
|
|
158
|
+
groups.push([]);
|
|
159
|
+
currentSize = 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
groups[groups.length - 1].push(path);
|
|
163
|
+
currentSize += size;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
138
167
|
for (let i = 0; i < groups.length; i++) {
|
|
139
168
|
let group = groups[i];
|
|
140
169
|
let time = Date.now();
|