From 458a7ec199e1475086e1a0b7f3958dffa5a2adbb Mon Sep 17 00:00:00 2001 From: Maltimore Date: Sun, 29 Jun 2025 21:39:33 +0200 Subject: [PATCH] refactor: reduce org file loading time --- lua/telescope-orgmode/entry_maker/orgfiles.lua | 7 ++----- lua/telescope-orgmode/org.lua | 9 ++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lua/telescope-orgmode/entry_maker/orgfiles.lua b/lua/telescope-orgmode/entry_maker/orgfiles.lua index d29adc0..4673b30 100644 --- a/lua/telescope-orgmode/entry_maker/orgfiles.lua +++ b/lua/telescope-orgmode/entry_maker/orgfiles.lua @@ -4,17 +4,14 @@ local entry_display = require('telescope.pickers.entry_display') local M = {} ----@param file_results { file: OrgApiFile, filename: string }[] +---@param file_results { filename: string, title: string, headline: string }[] ---@return OrgFileEntry[] local function index_orgfiles(file_results) local results = {} for _, file_entry in ipairs(file_results) do local entry = { - file = file_entry.file, filename = file_entry.filename, - -- not beautiful to access a private property, but this is the only way to get the title - ---@diagnostic disable-next-line: invisible, undefined-field - title = file_entry.file._file:get_directive('TITLE') or nil, + title = file_entry.title, headline = nil, } table.insert(results, entry) diff --git a/lua/telescope-orgmode/org.lua b/lua/telescope-orgmode/org.lua index 1568d79..294b5ed 100644 --- a/lua/telescope-orgmode/org.lua +++ b/lua/telescope-orgmode/org.lua @@ -3,15 +3,14 @@ local OrgApi = require('orgmode.api') local M = {} function M.load_files(opts) - ---@type { file: OrgApiFile, filename: string, last_used: number }[] + ---@type { filename: string, last_used: number, title: string }[] local file_results = vim.tbl_map(function(file) - local file_stat = vim.uv.fs_stat(file.filename) or 0 - return { file = file, filename = file.filename, last_used = file_stat.mtime.sec } - end, OrgApi.load()) + return { filename = file.filename, last_used = file.metadata.mtime, title = file:get_title() } + end, require('orgmode').files:all()) if not opts.archived then file_results = vim.tbl_filter(function(entry) - return not entry.file.is_archive_file + return not (vim.fn.fnamemodify(entry.filename, ':e') == 'org_archive') end, file_results) end