tt-help-cli-ycl 1.3.19 → 1.3.20

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-help-cli-ycl",
3
- "version": "1.3.19",
3
+ "version": "1.3.20",
4
4
  "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
5
  "type": "module",
6
6
  "bin": {
@@ -138,69 +138,44 @@ export function createStore(filePath) {
138
138
  }
139
139
  }
140
140
 
141
- // 异步 save:不阻塞事件循环,排队保证顺序
142
- // 多次 save 调用之间如果已有 save 在进行,只标记需要再次保存
143
- let saveInFlight = false;
144
- let pendingSave = false;
145
-
146
141
  function save() {
147
142
  if (!filePath) return;
148
- if (saveInFlight) {
149
- pendingSave = true;
150
- return;
151
- }
152
- doSave();
153
- }
154
-
155
- async function doSave() {
156
- saveInFlight = true;
157
143
  const resolved = path.resolve(filePath);
158
144
 
159
- try {
160
- // done 用户归档到独立文件
161
- if (doneArchivePath && data.length > 1000) {
162
- const active = [];
163
- const toArchive = [];
164
- for (const u of data) {
165
- if (u.status === 'done') {
166
- toArchive.push(u);
167
- } else {
168
- active.push(u);
169
- }
145
+ // 将 done 用户归档到独立文件
146
+ if (doneArchivePath && data.length > 1000) {
147
+ const active = [];
148
+ const toArchive = [];
149
+ for (const u of data) {
150
+ if (u.status === 'done') {
151
+ toArchive.push(u);
152
+ } else {
153
+ active.push(u);
170
154
  }
171
- if (toArchive.length > 0) {
172
- doneArchive = doneArchive.concat(toArchive);
173
- data.length = 0;
174
- data.push(...active);
175
- rebuildIndex();
176
- doneUidIndex = new Map();
177
- for (let i = 0; i < doneArchive.length; i++) {
178
- doneUidIndex.set(doneArchive[i].uniqueId, i);
179
- }
155
+ }
156
+ if (toArchive.length > 0) {
157
+ doneArchive = doneArchive.concat(toArchive);
158
+ data = active;
159
+ rebuildIndex();
160
+ // 重建 done 归档索引
161
+ doneUidIndex = new Map();
162
+ for (let i = 0; i < doneArchive.length; i++) {
163
+ doneUidIndex.set(doneArchive[i].uniqueId, i);
180
164
  }
181
165
  }
166
+ }
182
167
 
183
- const json = JSON.stringify(data);
184
- const tmpPath = resolved + '.tmp';
185
- await fs.promises.writeFile(tmpPath, json, 'utf-8');
186
- await fs.promises.rename(tmpPath, resolved);
187
-
188
- // 写 done 归档
189
- if (doneArchivePath && doneArchive.length > 0) {
190
- const doneJson = JSON.stringify(doneArchive);
191
- const doneTmp = doneArchivePath + '.tmp';
192
- await fs.promises.writeFile(doneTmp, doneJson, 'utf-8');
193
- await fs.promises.rename(doneTmp, doneArchivePath);
194
- }
195
- } catch (e) {
196
- console.error(`[DataStore] save error: ${e.message}`);
197
- } finally {
198
- saveInFlight = false;
199
- // 如果有排队的 save,继续执行
200
- if (pendingSave) {
201
- pendingSave = false;
202
- doSave();
203
- }
168
+ const json = JSON.stringify(data);
169
+ const tmpPath = resolved + '.tmp';
170
+ fs.writeFileSync(tmpPath, json, 'utf-8');
171
+ fs.renameSync(tmpPath, resolved);
172
+
173
+ // 写 done 归档
174
+ if (doneArchivePath && doneArchive.length > 0) {
175
+ const doneJson = JSON.stringify(doneArchive);
176
+ const doneTmp = doneArchivePath + '.tmp';
177
+ fs.writeFileSync(doneTmp, doneJson, 'utf-8');
178
+ fs.renameSync(doneTmp, doneArchivePath);
204
179
  }
205
180
  }
206
181