Diff

plugins/mod_storage_memory.lua @ 9997:7c4631d7b6fb

mod_storage_internal,memory: Only return total count if requested
author Kim Alvefur <zash@zash.se>
date Sun, 05 May 2019 08:12:16 +0200
parent 9906:d0b58bdd6c86
child 10019:c30c81176752
line wrap: on
line diff
--- a/plugins/mod_storage_memory.lua	Sat May 04 04:48:40 2019 +0200
+++ b/plugins/mod_storage_memory.lua	Sun May 05 08:12:16 2019 +0200
@@ -90,9 +90,14 @@
 function archive_store:find(username, query)
 	local items = self.store[username or NULL];
 	if not items then
-		return function () end, 0;
+		if query then
+			if query.total then
+				return function () end, 0;
+			end
+		end
+		return function () end;
 	end
-	local count = #items;
+	local count = nil;
 	local i = 0;
 	if query then
 		items = array():append(items);
@@ -116,11 +121,13 @@
 				return item.when <= query["end"];
 			end);
 		end
-		count = #items;
+		if query.total then
+			count = #items;
+		end
 		if query.reverse then
 			items:reverse();
 			if query.before then
-				for j = 1, count do
+				for j = 1, #items do
 					if (items[j].key or tostring(j)) == query.before then
 						i = j;
 						break;
@@ -128,7 +135,7 @@
 				end
 			end
 		elseif query.after then
-			for j = 1, count do
+			for j = 1, #items do
 				if (items[j].key or tostring(j)) == query.after then
 					i = j;
 					break;