tt-help-cli-ycl 1.4.34 → 1.4.35
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/src/watch/data-store.js +29 -12
package/package.json
CHANGED
package/src/watch/data-store.js
CHANGED
|
@@ -2334,9 +2334,12 @@ export function createStore(filePath, options = {}) {
|
|
|
2334
2334
|
const defaultTime = new Date("2016-01-01T00:00:00Z").getTime();
|
|
2335
2335
|
const targetLocations = locations || DEFAULT_TARGET_LOCATIONS;
|
|
2336
2336
|
const placeholders = targetLocations.map(() => "?").join(",");
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2337
|
+
|
|
2338
|
+
// 事务:SELECT + 立即 UPDATE refresh_time,防止多客户端重复领取
|
|
2339
|
+
const rows = getDb().transaction(() => {
|
|
2340
|
+
const selected = getDb()
|
|
2341
|
+
.prepare(
|
|
2342
|
+
`
|
|
2340
2343
|
SELECT unique_id, nickname, video_count, COALESCE(refresh_time, ?) AS refresh_time
|
|
2341
2344
|
FROM jobs
|
|
2342
2345
|
WHERE tt_seller = 1
|
|
@@ -2347,15 +2350,29 @@ export function createStore(filePath, options = {}) {
|
|
|
2347
2350
|
ORDER BY COALESCE(refresh_time, ?) ASC
|
|
2348
2351
|
LIMIT ?
|
|
2349
2352
|
`,
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2353
|
+
)
|
|
2354
|
+
.all(
|
|
2355
|
+
defaultTime,
|
|
2356
|
+
...targetLocations,
|
|
2357
|
+
defaultTime,
|
|
2358
|
+
threshold,
|
|
2359
|
+
defaultTime,
|
|
2360
|
+
limit,
|
|
2361
|
+
);
|
|
2362
|
+
|
|
2363
|
+
if (selected.length > 0) {
|
|
2364
|
+
const ids = selected.map((r) => r.unique_id);
|
|
2365
|
+
const idPlaceholders = ids.map(() => "?").join(",");
|
|
2366
|
+
getDb()
|
|
2367
|
+
.prepare(
|
|
2368
|
+
`UPDATE jobs SET refresh_time = ?, updated_at = ? WHERE unique_id IN (${idPlaceholders})`,
|
|
2369
|
+
)
|
|
2370
|
+
.run(now, now, ...ids);
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
return selected;
|
|
2374
|
+
})();
|
|
2375
|
+
|
|
2359
2376
|
return rows.map((r) => ({
|
|
2360
2377
|
uniqueId: r.unique_id,
|
|
2361
2378
|
nickname: r.nickname,
|