From 6480d37ec03081592ddb0a45657d8a60c990dae3 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 15 Sep 2025 18:27:04 -0400 Subject: [PATCH] fix: make optimization for is_empty conditional Usually Puter has a UID by this point, but if it ever doesn't we can fall back on using the path with a `LIKE ? + '%'` query. However, users before a particular date might have fsentries without a path, so we need to perform a check on the user's timestamp to avoid issues. --- .../src/filesystem/hl_operations/hl_stat.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/backend/src/filesystem/hl_operations/hl_stat.js b/src/backend/src/filesystem/hl_operations/hl_stat.js index 2bdb3a306..499221bc9 100644 --- a/src/backend/src/filesystem/hl_operations/hl_stat.js +++ b/src/backend/src/filesystem/hl_operations/hl_stat.js @@ -20,6 +20,7 @@ const { Context } = require("../../util/context"); const { HLFilesystemOperation } = require("./definitions"); const APIError = require('../../api/APIError'); const { ECMAP } = require("../ECMAP"); +const { NodeUIDSelector } = require("../node/selectors"); class HLStat extends HLFilesystemOperation { static MODULES = { @@ -45,11 +46,25 @@ class HLStat extends HLFilesystemOperation { return_versions, return_size, } = this.values; + + const maybe_uid_selector = subject.get_selector_of_type(NodeUIDSelector); + + // users created before 2025-07-30 might have fsentries with NULL paths. + // we can remove this check once that is fixed. + const user_unix_ts = Number((''+Date.parse(Context.get('actor')?.type?.user?.timestamp)).slice(0, -3)); + const paths_are_fine = user_unix_ts >= 1722385593; - await Promise.all([ - subject.fetchEntry(), - subject.fetchIsEmpty(), - ]); + if ( maybe_uid_selector || paths_are_fine ) { + // We are able to fetch the entry and is_empty simultaneously + await Promise.all([ + subject.fetchEntry(), + subject.fetchIsEmpty(), + ]); + } else { + // We need the entry first in order for is_empty to work correctly + await subject.fetchEntry(); + await subject.fetchIsEmpty(); + } // file not found if( ! subject.found ) throw APIError.create('subject_does_not_exist');