Comparison

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
comparison
equal deleted inserted replaced
9996:9bb1bed3e8e3 9997:7c4631d7b6fb
88 end 88 end
89 89
90 function archive_store:find(username, query) 90 function archive_store:find(username, query)
91 local items = self.store[username or NULL]; 91 local items = self.store[username or NULL];
92 if not items then 92 if not items then
93 return function () end, 0; 93 if query then
94 end 94 if query.total then
95 local count = #items; 95 return function () end, 0;
96 end
97 end
98 return function () end;
99 end
100 local count = nil;
96 local i = 0; 101 local i = 0;
97 if query then 102 if query then
98 items = array():append(items); 103 items = array():append(items);
99 if query.key then 104 if query.key then
100 items:filter(function (item) 105 items:filter(function (item)
114 if query["end"] then 119 if query["end"] then
115 items:filter(function (item) 120 items:filter(function (item)
116 return item.when <= query["end"]; 121 return item.when <= query["end"];
117 end); 122 end);
118 end 123 end
119 count = #items; 124 if query.total then
125 count = #items;
126 end
120 if query.reverse then 127 if query.reverse then
121 items:reverse(); 128 items:reverse();
122 if query.before then 129 if query.before then
123 for j = 1, count do 130 for j = 1, #items do
124 if (items[j].key or tostring(j)) == query.before then 131 if (items[j].key or tostring(j)) == query.before then
125 i = j; 132 i = j;
126 break; 133 break;
127 end 134 end
128 end 135 end
129 end 136 end
130 elseif query.after then 137 elseif query.after then
131 for j = 1, count do 138 for j = 1, #items do
132 if (items[j].key or tostring(j)) == query.after then 139 if (items[j].key or tostring(j)) == query.after then
133 i = j; 140 i = j;
134 break; 141 break;
135 end 142 end
136 end 143 end