plugins/mod_storage_memory.lua
changeset 10001 7c4631d7b6fb
parent 9910 d0b58bdd6c86
child 10023 c30c81176752
--- 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;