mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-12 03:43:01 +02:00
#801 - Faster folder processing
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
### 🐞 Fixes
|
||||
|
||||
- [#796](https://github.com/estruyf/vscode-front-matter/issues/796): Fix issue in retrieving folders/files on dashboard load
|
||||
- [#801](https://github.com/estruyf/vscode-front-matter/issues/801): Faster folder processing on updates
|
||||
|
||||
## [10.1.0] - 2024-04-11 - [Release notes](https://beta.frontmatter.codes/updates/v10.1.0)
|
||||
|
||||
|
||||
+21
-1
@@ -32,6 +32,13 @@ import { LocalizationKey } from '../localization';
|
||||
export const WORKSPACE_PLACEHOLDER = `[[workspace]]`;
|
||||
|
||||
export class Folders {
|
||||
private static _folders: ContentFolder[] = [];
|
||||
|
||||
public static clearCached() {
|
||||
Logger.verbose(`Folders:clearCached`);
|
||||
Folders._folders = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a media folder
|
||||
* @returns
|
||||
@@ -282,6 +289,7 @@ export class Folders {
|
||||
* Get the registered folders information
|
||||
*/
|
||||
public static async getInfo(limit?: number): Promise<FolderInfo[] | null> {
|
||||
Logger.verbose('Folders:getInfo:start');
|
||||
const supportedFiles = Settings.get<string[]>(SETTING_CONTENT_SUPPORTED_FILETYPES);
|
||||
const folders = Folders.get();
|
||||
|
||||
@@ -295,9 +303,11 @@ export class Folders {
|
||||
}
|
||||
}
|
||||
|
||||
Logger.verbose('Folders:getInfo:end');
|
||||
return folderInfo;
|
||||
}
|
||||
|
||||
Logger.verbose('Folders:getInfo:end - no folders found');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -306,6 +316,13 @@ export class Folders {
|
||||
* @returns
|
||||
*/
|
||||
public static get(): ContentFolder[] {
|
||||
Logger.verbose('Folders:get:start');
|
||||
|
||||
if (Folders._folders.length > 0) {
|
||||
Logger.verbose('Folders:get:end - cached folders');
|
||||
return Folders._folders;
|
||||
}
|
||||
|
||||
const wsFolder = Folders.getWorkspaceFolder();
|
||||
let folders: ContentFolder[] = Settings.get(SETTING_CONTENT_PAGE_FOLDERS) as ContentFolder[];
|
||||
const i18nSettings = Settings.get<I18nConfig[]>(SETTING_CONTENT_I18N);
|
||||
@@ -323,6 +340,7 @@ export class Folders {
|
||||
|
||||
const folderPath = Folders.absWsFolder(folder, wsFolder);
|
||||
const subFolders = glob.sync(folderPath, { ignore: '**/node_modules/**' });
|
||||
// const subFolders = await Folders.findFolders(folderPath);
|
||||
for (const subFolder of subFolders) {
|
||||
const subFolderPath = parseWinPath(subFolder);
|
||||
|
||||
@@ -417,7 +435,9 @@ export class Folders {
|
||||
}
|
||||
});
|
||||
|
||||
return contentFolders.filter((folder) => folder !== null) as ContentFolder[];
|
||||
Logger.verbose('Folders:get:end');
|
||||
Folders._folders = contentFolders.filter((folder) => folder !== null) as ContentFolder[];
|
||||
return Folders._folders;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1139,6 +1139,9 @@ export class Settings {
|
||||
*/
|
||||
private static async reloadConfig(debounced: boolean = true) {
|
||||
Logger.info(`Reloading config...`);
|
||||
// Clear the folder cache as we need to see the latest folders
|
||||
Folders.clearCached();
|
||||
|
||||
if (Settings.readConfigPromise === undefined) {
|
||||
Settings.readConfigPromise = Settings.readConfig();
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ export class PagesParser {
|
||||
public static async parsePages() {
|
||||
Logger.info('PagesParser:parsePages:start');
|
||||
i18n.clearFiles();
|
||||
Folders.clearCached();
|
||||
const ext = Extension.getInstance();
|
||||
|
||||
// Update the dashboard with the fresh data
|
||||
@@ -138,6 +139,7 @@ export class PagesParser {
|
||||
PagesParser.allPages = [...pages];
|
||||
PagesParser.pagesStatusBar.hide();
|
||||
|
||||
Folders.clearCached();
|
||||
Logger.info('PagesParser:parsePages:end');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user