From a5882889ddcde67e64b0a06216288775f598a400 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Sat, 13 Sep 2025 20:27:22 -0400 Subject: [PATCH] perf: make stat really fast --- src/backend/src/filesystem/ECMAP.js | 4 ++++ .../src/filesystem/hl_operations/hl_stat.js | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/backend/src/filesystem/ECMAP.js b/src/backend/src/filesystem/ECMAP.js index 2a8a3710..f6c9150f 100644 --- a/src/backend/src/filesystem/ECMAP.js +++ b/src/backend/src/filesystem/ECMAP.js @@ -81,6 +81,10 @@ class ECMAP { } } + store_fsNodeContext (node) { + this.store_fsNodeContext_to_selector(node.selector, node); + } + static async arun (cb) { let context = Context.get(); if ( ! context.get(this.SYMBOL) ) { diff --git a/src/backend/src/filesystem/hl_operations/hl_stat.js b/src/backend/src/filesystem/hl_operations/hl_stat.js index 53419aea..2bdb3a30 100644 --- a/src/backend/src/filesystem/hl_operations/hl_stat.js +++ b/src/backend/src/filesystem/hl_operations/hl_stat.js @@ -19,6 +19,7 @@ const { Context } = require("../../util/context"); const { HLFilesystemOperation } = require("./definitions"); const APIError = require('../../api/APIError'); +const { ECMAP } = require("../ECMAP"); class HLStat extends HLFilesystemOperation { static MODULES = { @@ -26,6 +27,16 @@ class HLStat extends HLFilesystemOperation { } async _run () { + return await ECMAP.arun(async () => { + const ecmap = Context.get(ECMAP.SYMBOL); + ecmap.store_fsNodeContext(this.values.subject); + return await this.__run(); + }); + } + // async _run () { + // return await this.__run(); + // } + async __run () { const { subject, user, return_subdomains, @@ -35,7 +46,10 @@ class HLStat extends HLFilesystemOperation { return_size, } = this.values; - await subject.fetchEntry(); + await Promise.all([ + subject.fetchEntry(), + subject.fetchIsEmpty(), + ]); // file not found if( ! subject.found ) throw APIError.create('subject_does_not_exist'); @@ -61,8 +75,6 @@ class HLStat extends HLFilesystemOperation { } if (return_versions) await subject.fetchVersions(); - await subject.fetchIsEmpty(); - return await subject.getSafeEntry(); } }