Software /
code /
prosody
Comparison
plugins/mod_storage_internal.lua @ 13847:cbd234461c41 13.0
mod_storage_internal: Fix queries with only start returning extra items
Queries with start > last item would return one item, because there's
some boundary condition in binary_search().
This is here fixed by always applying filters that omit items outside
the requested range.
See also 2374c7665d0b
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 14 Apr 2025 15:10:29 +0200 |
parent | 13761:8f516d20d288 |
comparison
equal
deleted
inserted
replaced
13845:2558be2daaca | 13847:cbd234461c41 |
---|---|
203 local wi = binary_search(list, function(item) | 203 local wi = binary_search(list, function(item) |
204 local when = item.when or datetime.parse(item.attr.stamp); | 204 local when = item.when or datetime.parse(item.attr.stamp); |
205 return query.start - when; | 205 return query.start - when; |
206 end); | 206 end); |
207 i = wi - 1; | 207 i = wi - 1; |
208 else | 208 end |
209 iter = it.filter(function(item) | 209 iter = it.filter(function(item) |
210 local when = item.when or datetime.parse(item.attr.stamp); | 210 local when = item.when or datetime.parse(item.attr.stamp); |
211 return when >= query.start; | 211 return when >= query.start; |
212 end, iter); | 212 end, iter); |
213 end | |
214 end | 213 end |
215 if query["end"] then | 214 if query["end"] then |
216 if query.reverse then | 215 if query.reverse then |
217 local wi = binary_search(list, function(item) | 216 local wi = binary_search(list, function(item) |
218 local when = item.when or datetime.parse(item.attr.stamp); | 217 local when = item.when or datetime.parse(item.attr.stamp); |
219 return query["end"] - when; | 218 return query["end"] - when; |
220 end); | 219 end); |
221 if wi then | 220 if wi then |
222 i = wi + 1; | 221 i = wi + 1; |
223 end | 222 end |
224 else | 223 end |
225 iter = it.filter(function(item) | 224 iter = it.filter(function(item) |
226 local when = item.when or datetime.parse(item.attr.stamp); | 225 local when = item.when or datetime.parse(item.attr.stamp); |
227 return when <= query["end"]; | 226 return when <= query["end"]; |
228 end, iter); | 227 end, iter); |
229 end | |
230 end | 228 end |
231 if query.after then | 229 if query.after then |
232 local found = false; | 230 local found = false; |
233 iter = it.filter(function(item) | 231 iter = it.filter(function(item) |
234 local found_after = found; | 232 local found_after = found; |