From 06addc9a735417f7194a0e579b05bc0c5d530a00 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 10 Nov 2017 09:44:30 +0100 Subject: mod_storage_internal: Optimize truncation --- plugins/mod_storage_internal.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'plugins/mod_storage_internal.lua') diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua index 55a4bfeb..4395c3f0 100644 --- a/plugins/mod_storage_internal.lua +++ b/plugins/mod_storage_internal.lua @@ -195,14 +195,15 @@ function archive:delete(username, query) if query.reverse then -- Before: { 1, 2, 3, 4, 5, } -- After: { 1, 2, 3 } - while #items > query.truncate do - table.remove(items); + for i = #items, query.truncate + 1, -1 do + items[i] = nil; end else -- Before: { 1, 2, 3, 4, 5, } -- After: { 3, 4, 5 } - while #items > query.truncate do - table.remove(items, 1); + local offset = #items - query.truncate; + for i = 1, #items do + items[i] = items[i+offset]; end end end -- cgit v1.2.3