From 944b4b105ce834b61f3eabe1f221be7aec458ca0 Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Fri, 1 Nov 2024 16:01:35 +0800 Subject: [PATCH] CephFSDocumentsProvider: cheaper getDocumentType --- .../org/safcephfs/CephFSDocumentsProvider.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/safcephfs/CephFSDocumentsProvider.java b/src/main/java/org/safcephfs/CephFSDocumentsProvider.java index 2a0afab..307453c 100644 --- a/src/main/java/org/safcephfs/CephFSDocumentsProvider.java +++ b/src/main/java/org/safcephfs/CephFSDocumentsProvider.java @@ -443,6 +443,21 @@ public class CephFSDocumentsProvider extends DocumentsProvider { return result; } + // default implementation query without projection, which is costly + // TODO try to upstream the idea? + public String getDocumentType(String documentId) + throws FileNotFoundException { + try (var c = new UncheckedAutoCloseable(queryDocument( + documentId, new String[]{Document.COLUMN_MIME_TYPE}))) { + if (c.c().moveToFirst()) { + return c.c().getString( + c.c().getColumnIndexOrThrow(Document.COLUMN_MIME_TYPE)); + } else { + return null; + } + } + } + private long getXattrULL(String path, String name) throws FileNotFoundException { var buf = new byte[32]; -- 2.45.2