Skip to content

Commit

Permalink
#801 - Faster folder processing
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Apr 29, 2024
1 parent dee732f commit f637def
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 21 additions & 1 deletion src/commands/Folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand All @@ -295,9 +303,11 @@ export class Folders {
}
}

Logger.verbose('Folders:getInfo:end');
return folderInfo;
}

Logger.verbose('Folders:getInfo:end - no folders found');
return null;
}

Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/SettingsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions src/services/PagesParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -138,6 +139,7 @@ export class PagesParser {
PagesParser.allPages = [...pages];
PagesParser.pagesStatusBar.hide();

Folders.clearCached();
Logger.info('PagesParser:parsePages:end');
}

Expand Down

0 comments on commit f637def

Please sign in to comment.