Skip to content

Commit de55372

Browse files
优化导入数据
1 parent 0f9a798 commit de55372

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
![Instructions.gif](https://s1.ax1x.com/2020/08/19/dQ8R3t.gif)
1313

14+
### v1.4.0
15+
16+
- 优化导入数据
17+
1418
### v1.3.9
1519

1620
- 我的自选基金新增支持s前缀搜索过滤自选基金,如s001071

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "utools-fund",
3-
"version": "v1.3.9",
3+
"version": "v1.4.0",
44
"description": "自选基金助手",
55
"main": "main.ts",
66
"scripts": {
@@ -25,4 +25,4 @@
2525
"dependencies": {
2626
"axios": "^0.19.2"
2727
}
28-
}
28+
}

src/Helper/FundDBHelper.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ const FUND_DB_PRE_FIX = 'fund_';
55

66
export default class FundDBHelper {
77
static set(data: IFundEnt) {
8-
return utools.db.put({
8+
const db: DBItem<IFundEnt> = {
99
_id: `${FUND_DB_PRE_FIX}${data.id}`,
1010
data,
11-
});
11+
};
12+
const existDB = FundDBHelper.get(data.id);
13+
if (existDB) {
14+
db._rev = existDB._rev;
15+
}
16+
return utools.db.put(db);
1217
}
1318

1419
static setList(data: IFundEnt[]) {
20+
const existDBList = FundDBHelper.getAll();
1521
const dbList = data.map(x => {
1622
const db: DBItem<IFundEnt> = {
1723
_id: `${FUND_DB_PRE_FIX}${x.id}`,
1824
data: x,
1925
};
26+
const existDB = existDBList.find(d => d.data.id === x.id);
27+
if (existDB) {
28+
db._rev = existDB._rev;
29+
}
2030
return db;
2131
});
2232
return utools.db.bulkDocs(dbList);

src/features/fundImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const fundImport: TplFeature = {
1111
enter: async (action, callbackSetList) => {
1212
if (action.type === 'files') {
1313
const jsonFile: FilesPayload = action.payload[0];
14-
if (jsonFile.isFile && jsonFile.name === 'fund_data.json') {
14+
if (jsonFile.isFile && jsonFile.name.includes('fund_data.json')) {
1515
const fundJsonStr = readFileSync(jsonFile.path, { encoding: 'utf-8' });
1616
const fundData: IFundEnt[] = JSON.parse(fundJsonStr);
1717
FundDBHelper.setList(fundData);

0 commit comments

Comments
 (0)