Skip to content
Browse files

Adding support for "limit" in get_node_history to speed up the time to

lookup latest modification time.
  • Loading branch information...
1 parent 4e5ea85 commit ad47cc7c63eefd1a2501913933bedfac1f3aa186 @yuri committed
Showing with 30 additions and 10 deletions.
  1. +20 −6 versium-git/lua/versium/git.lua
  2. +10 −4 versium/lua/versium/filedir.lua
View
26 versium-git/lua/versium/git.lua
@@ -156,16 +156,18 @@ end
-----------------------------------------------------------------------------
function GitVersium:get_node_info(id, version)
assert(id)
- local history = self:get_node_history(id) or {}
- assert(#history > 0, "History should have at least one item in it")
-
- if version then
+
+ if version then
+ local history = self:get_node_history(id) or {}
+ assert(#history > 0, "History should have at least one item in it")
for i, commit in ipairs(history) do
if commit.version == version then
return commit
end
end
else
+ local history = self:get_node_history(id, nil, 1) or {}
+ assert(#history > 0, "History should have at least one item in it")
return history[1] -- i.e., the _latest_ version
end
end
@@ -263,7 +265,7 @@ end
-- @return a list of tables representing the versions (the list
-- will be empty if the node doesn't exist).
-----------------------------------------------------------------------------
-function GitVersium:get_node_history(id, prefix)
+function GitVersium:get_node_history(id, prefix, limit)
assert(id)
if not self:node_exists(id) then return nil end
local path = self:id2path(id)
@@ -284,13 +286,25 @@ function GitVersium:get_node_history(id, prefix)
.."\nreturn commits"
local history = loadstring(history_as_lua)()
+
+ if limit then
+ local old_history = history
+ history = {}
+ for i, commit in ipairs(old_history) do
+ if i <= limit then
+ table.insert(history, commit)
+ end
+ end
+ end
+
local divider="^(.*)%-%-%-extra%-fields%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-%-(.*)$"
for i, commit in ipairs(history) do
commit.comment = commit.comment:gsub("\n\n<unknown>$", "")
+ commit.timestamp = os.date("!%Y-%m-%d %H:%M:%S", commit.timestamp)
+
local before, after = commit.comment:match(divider)
if before then
commit.comment = before
- commit.timestamp = os.date("!%Y-%m-%d %H:%M:%S", commit.timestamp)
local f, err=loadstring(after)
if err then return nil, err end
setfenv(f, {})
View
14 versium/lua/versium/filedir.lua
@@ -147,8 +147,13 @@ end
-----------------------------------------------------------------------------
function FileDirVersium:get_node_info(id, version)
assert(id)
- local history = self:get_node_history(id) or {}
- assert(#history > 0, "History should have at least one item in it")
+ local history
+ if not version then
+ history = self:get_node_history(id, nil, 1) or {}
+ else
+ history = self:get_node_history(id) or {}
+ end
+ if not #history==0 then return nil end
if version then
for i, commit in ipairs(history) do
@@ -242,15 +247,16 @@ end
--
-- @param id the id of the node.
-- @param prefix time prefix.
+-- @param limit the max number of history items to return
-- @return a list of tables representing the versions (the list
-- will be empty if the node doesn't exist).
-----------------------------------------------------------------------------
-function FileDirVersium:get_node_history(id, prefix)
+function FileDirVersium:get_node_history(id, prefix, limit)
assert(id)
if not self:node_exists(id) then return nil end
local raw_history = get_raw_history(self.dir, id)
assert(raw_history:len() > 0)
- return parse_history(raw_history, prefix)
+ return parse_history(raw_history, prefix, limit)
end

0 comments on commit ad47cc7

Please sign in to comment.
Something went wrong with that request. Please try again.