Comparison

plugins/mod_storage_internal.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 9903:2c5546cc5c70
child 10001:55f5588d71c6
comparison
equal deleted inserted replaced
9996:9bb1bed3e8e3 9997:7c4631d7b6fb
122 function archive:find(username, query) 122 function archive:find(username, query)
123 local items, err = datamanager.list_load(username, host, self.store); 123 local items, err = datamanager.list_load(username, host, self.store);
124 if not items then 124 if not items then
125 if err then 125 if err then
126 return items, err; 126 return items, err;
127 else 127 elseif query then
128 return function () end, 0; 128 if query.total then
129 end 129 return function () end, 0;
130 end 130 end
131 local count = #items; 131 end
132 return function () end;
133 end
134 local count = nil;
132 local i = 0; 135 local i = 0;
133 if query then 136 if query then
134 items = array(items); 137 items = array(items);
135 if query.key then 138 if query.key then
136 items:filter(function (item) 139 items:filter(function (item)
150 if query["end"] then 153 if query["end"] then
151 items:filter(function (item) 154 items:filter(function (item)
152 return item.when <= query["end"]; 155 return item.when <= query["end"];
153 end); 156 end);
154 end 157 end
155 count = #items; 158 if query.total then
159 count = #items;
160 end
156 if query.reverse then 161 if query.reverse then
157 items:reverse(); 162 items:reverse();
158 if query.before then 163 if query.before then
159 for j = 1, count do 164 for j = 1, #items do
160 if (items[j].key or tostring(j)) == query.before then 165 if (items[j].key or tostring(j)) == query.before then
161 i = j; 166 i = j;
162 break; 167 break;
163 end 168 end
164 end 169 end
165 end 170 end
166 elseif query.after then 171 elseif query.after then
167 for j = 1, count do 172 for j = 1, #items do
168 if (items[j].key or tostring(j)) == query.after then 173 if (items[j].key or tostring(j)) == query.after then
169 i = j; 174 i = j;
170 break; 175 break;
171 end 176 end
172 end 177 end