mod_storage_internal: Allow truncating deletion at the beginning or end of an archive store
authorKim Alvefur <zash@zash.se>
Thu, 09 Nov 2017 01:42:01 +0100
changeset 8396 b6a7b83f8d87
parent 8395 ff8e122526f4
child 8397 4892c22403d5
mod_storage_internal: Allow truncating deletion at the beginning or end of an archive store
plugins/mod_storage_internal.lua
--- a/plugins/mod_storage_internal.lua	Sun Nov 19 20:51:53 2017 +0100
+++ b/plugins/mod_storage_internal.lua	Thu Nov 09 01:42:01 2017 +0100
@@ -191,6 +191,21 @@
 				return item.when > query["end"];
 			end);
 		end
+		if query.truncate then
+			if query.reverse then
+				-- Before: { 1, 2, 3, 4, 5, }
+				-- After: { 1, 2, 3 }
+				while #items > query.truncate do
+					table.remove(items);
+				end
+			else
+				-- Before: { 1, 2, 3, 4, 5, }
+				-- After: { 3, 4, 5 }
+				while #items > query.truncate do
+					table.remove(items, 1);
+				end
+			end
+		end
 	end
 	local count = count_before - #items;
 	local ok, err = datamanager.list_store(username, host, self.store, items);