Skip to content

Commit

Permalink
fix: 删除缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
aooiuu committed May 12, 2024
1 parent 1134501 commit 279eac3
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
2 changes: 1 addition & 1 deletion packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "any-reader",
"description": "自定义规则多站点聚合搜索阅读小说、漫画。包含JS规则解析库和VSCode插件。支持本地小说 TXT、EPUB",
"icon": "resources/icon.png",
"version": "0.7.1",
"version": "0.7.2",
"preview": true,
"publisher": "aooiu",
"qna": "https://github.com/aooiuu/any-reader/issues",
Expand Down
10 changes: 0 additions & 10 deletions packages/vscode/src/sidebar/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ChapterItem, Rule } from '@any-reader/core';
export class BookProvider implements vscode.TreeDataProvider<TreeNode> {
readonly _onDidChangeTreeData = new vscode.EventEmitter<TreeNode | undefined>();
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
readonly cache = new Map();

refresh(): void {
this._onDidChangeTreeData.fire(undefined);
Expand All @@ -34,32 +33,23 @@ export class BookProvider implements vscode.TreeDataProvider<TreeNode> {
};
}

// 获取缓存列表
getChildrenCache(ruleId: string, url: string) {
const key = `${ruleId}@${url}`;
return this.cache.get(key) || this.cache.get('_') || [];
}

async getChildren(element?: TreeNode): Promise<TreeNode[]> {
if (!element) {
const items = await bookManager.getChildren();
return items;
} else {
const chapters = await bookManager.getChapter(element);
this.cache.set(`${element.rule.id}@${element.url}`, chapters);
return chapters;
}
}

setChapters(chapterItems: ChapterItem[], rule: Rule, url: string) {
this.cache.clear();
bookManager.list = chapterItems.map((chapterItem: ChapterItem) => ({
rule,
type: 2,
data: chapterItem,
url
}));
this.cache.set('_', bookManager.list);
this.refresh();
}
}
Expand Down
8 changes: 0 additions & 8 deletions packages/vscode/src/sidebar/localBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { COMMANDS } from '../constants';
class TreeDataProvider implements vscode.TreeDataProvider<TreeNode> {
readonly _onDidChangeTreeData = new vscode.EventEmitter<TreeNode | undefined>();
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
readonly cache = new Map();

async refresh(): Promise<void> {
this._onDidChangeTreeData.fire(undefined);
Expand Down Expand Up @@ -43,19 +42,12 @@ class TreeDataProvider implements vscode.TreeDataProvider<TreeNode> {
};
}

// 获取缓存列表
getChildrenCache(path: string) {
return this.cache.get(path) || [];
}

// 获取目录
async getChildren(item?: TreeNode): Promise<TreeNode[]> {
if (!item) {
this.cache.clear();
return getBookList();
} else {
const chapters = await getChapter(item.path).catch(() => []);
this.cache.set(item.path, chapters);
return chapters;
}
}
Expand Down

0 comments on commit 279eac3

Please sign in to comment.