Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/authentication/account-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { postCategoriesDataProvider } from '../tree-view-providers/post-categori
import { OauthApi } from '@/services/oauth.api';
import { CnblogsAuthenticationProvider } from '@/authentication/authentication-provider';
import { CnblogsAuthenticationSession } from '@/authentication/session';
import { BlogExportProvider } from '@/tree-view-providers/blog-export-provider';

const isAuthorizedStorageKey = 'isAuthorized';

Expand Down Expand Up @@ -38,6 +39,9 @@ class AccountManager extends vscode.Disposable {
accountViewDataProvider.fireTreeDataChangedEvent();
postsDataProvider.fireTreeDataChangedEvent(undefined);
postCategoriesDataProvider.fireTreeDataChangedEvent();
BlogExportProvider.optionalInstance
?.refreshRecords({ force: false, clearCache: true })
.catch(console.warn);
})
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/services/blog-export-records.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ export class BlogExportRecordsStore {
async refresh(
options?: BlogExportRecordsStore['list'] extends (opt: infer U) => unknown ? U : never
): Promise<BlogExportRecordList> {
await this.clearCache();
return this.list(options);
}

async clearCache(): Promise<void> {
if (this._cachedList) await this._cachedList.catch(() => false);

this._cachedList = null;
this._cached = null;
return this.list(options);
}

list({
Expand Down
27 changes: 26 additions & 1 deletion src/tree-view-providers/blog-export-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,38 @@ export class BlogExportProvider implements TreeDataProvider<BlogExportTreeItem>
return false;
}

async refreshRecords({ notifyOnError = true, force = true } = {}): Promise<boolean> {
/**
* Refresh the records of blog-export
* @param options
* @returns The boolean value which tell if the data has been refreshed
*/
async refreshRecords({
/**
* Tell if to raise a notify to the user when error response received during the refreshing process
*/
notifyOnError = true,
/**
* Tell should reload the cached data
*/
force = true,
/**
* Tell should remove the cached data
* **NOTE** only works with `force=false`, when `force=true`, the cached data will always be removed and the re-created
*/
clearCache = true,
} = {}): Promise<boolean> {
const hasCacheRefreshed = force
? await this._store
?.refresh()
.then(() => true)
.catch(e => (notifyOnError ? void AlertService.warning(`刷新博客备份失败记录, ${e}`) : undefined))
: clearCache
? await this._store?.clearCache().then(
() => true,
() => true
)
: true;

if (hasCacheRefreshed) this._treeDataChangedSource?.fire(null);

return hasCacheRefreshed ?? false;
Expand Down