Skip to content

Commit 71bbf20

Browse files
authored
fix(blog-export/records-list): clear cached data after authorized (#127)
1 parent fa09d73 commit 71bbf20

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/authentication/account-manager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { postCategoriesDataProvider } from '../tree-view-providers/post-categori
77
import { OauthApi } from '@/services/oauth.api';
88
import { CnblogsAuthenticationProvider } from '@/authentication/authentication-provider';
99
import { CnblogsAuthenticationSession } from '@/authentication/session';
10+
import { BlogExportProvider } from '@/tree-view-providers/blog-export-provider';
1011

1112
const isAuthorizedStorageKey = 'isAuthorized';
1213

@@ -38,6 +39,9 @@ class AccountManager extends vscode.Disposable {
3839
accountViewDataProvider.fireTreeDataChangedEvent();
3940
postsDataProvider.fireTreeDataChangedEvent(undefined);
4041
postCategoriesDataProvider.fireTreeDataChangedEvent();
42+
BlogExportProvider.optionalInstance
43+
?.refreshRecords({ force: false, clearCache: true })
44+
.catch(console.warn);
4145
})
4246
);
4347
}

src/services/blog-export-records.store.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ export class BlogExportRecordsStore {
1313
async refresh(
1414
options?: BlogExportRecordsStore['list'] extends (opt: infer U) => unknown ? U : never
1515
): Promise<BlogExportRecordList> {
16+
await this.clearCache();
17+
return this.list(options);
18+
}
19+
20+
async clearCache(): Promise<void> {
1621
if (this._cachedList) await this._cachedList.catch(() => false);
1722

1823
this._cachedList = null;
1924
this._cached = null;
20-
return this.list(options);
2125
}
2226

2327
list({

src/tree-view-providers/blog-export-provider.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,38 @@ export class BlogExportProvider implements TreeDataProvider<BlogExportTreeItem>
8383
return false;
8484
}
8585

86-
async refreshRecords({ notifyOnError = true, force = true } = {}): Promise<boolean> {
86+
/**
87+
* Refresh the records of blog-export
88+
* @param options
89+
* @returns The boolean value which tell if the data has been refreshed
90+
*/
91+
async refreshRecords({
92+
/**
93+
* Tell if to raise a notify to the user when error response received during the refreshing process
94+
*/
95+
notifyOnError = true,
96+
/**
97+
* Tell should reload the cached data
98+
*/
99+
force = true,
100+
/**
101+
* Tell should remove the cached data
102+
* **NOTE** only works with `force=false`, when `force=true`, the cached data will always be removed and the re-created
103+
*/
104+
clearCache = true,
105+
} = {}): Promise<boolean> {
87106
const hasCacheRefreshed = force
88107
? await this._store
89108
?.refresh()
90109
.then(() => true)
91110
.catch(e => (notifyOnError ? void AlertService.warning(`刷新博客备份失败记录, ${e}`) : undefined))
111+
: clearCache
112+
? await this._store?.clearCache().then(
113+
() => true,
114+
() => true
115+
)
92116
: true;
117+
93118
if (hasCacheRefreshed) this._treeDataChangedSource?.fire(null);
94119

95120
return hasCacheRefreshed ?? false;

0 commit comments

Comments
 (0)