Skip to content

Commit 6a53595

Browse files
MaltimoreSebastian Flügge
authored andcommitted
perf: reduce org file loading time
1 parent a73d9b7 commit 6a53595

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

lua/telescope-orgmode/entry_maker/orgfiles.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ local entry_display = require('telescope.pickers.entry_display')
44

55
local M = {}
66

7-
---@param file_results { file: OrgApiFile, filename: string }[]
7+
---@param file_results { filename: string, title: string, headline: string }[]
88
---@return OrgFileEntry[]
99
local function index_orgfiles(file_results)
1010
local results = {}
1111
for _, file_entry in ipairs(file_results) do
1212
local entry = {
13-
file = file_entry.file,
1413
filename = file_entry.filename,
15-
-- not beautiful to access a private property, but this is the only way to get the title
16-
---@diagnostic disable-next-line: invisible, undefined-field
17-
title = file_entry.file._file:get_directive('TITLE') or nil,
14+
title = file_entry.title,
1815
headline = nil,
1916
}
2017
table.insert(results, entry)

lua/telescope-orgmode/org.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ local OrgApi = require('orgmode.api')
33
local M = {}
44

55
function M.load_files(opts)
6-
---@type { file: OrgApiFile, filename: string, last_used: number }[]
6+
---@type { filename: string, last_used: number, title: string }[]
77
local file_results = vim.tbl_map(function(file)
8-
local file_stat = vim.uv.fs_stat(file.filename) or 0
9-
return { file = file, filename = file.filename, last_used = file_stat.mtime.sec }
10-
end, OrgApi.load())
8+
return { filename = file.filename, last_used = file.metadata.mtime, title = file:get_title() }
9+
end, require('orgmode').files:all())
1110

1211
if not opts.archived then
1312
file_results = vim.tbl_filter(function(entry)
14-
return not entry.file.is_archive_file
13+
return not (vim.fn.fnamemodify(entry.filename, ':e') == 'org_archive')
1514
end, file_results)
1615
end
1716

0 commit comments

Comments
 (0)