Software /
code /
prosody
Comparison
plugins/mod_storage_internal.lua @ 13262:9a86e7cbdd79
mod_storage_internal: Fix fast trimming of archive with exactly one item
This method would previously never delete the first (and only) item
since it works out which item should become the first item after the
trim operation, which doesn't make sense when all should be removed.
This also works as an optimization for when all the last item should be
trimmed, thus items should be removed.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 24 Sep 2023 13:41:54 +0200 |
parent | 13228:616c578c644f |
child | 13263:e77994e88940 |
comparison
equal
deleted
inserted
replaced
13261:7c62370dee9a | 13262:9a86e7cbdd79 |
---|---|
345 end | 345 end |
346 | 346 |
347 function archive:trim(username, to_when) | 347 function archive:trim(username, to_when) |
348 local list, err = datamanager.list_open(username, host, self.store); | 348 local list, err = datamanager.list_open(username, host, self.store); |
349 if not list then return list,err;end | 349 if not list then return list,err;end |
350 | |
351 -- shortcut: check if the last item should be trimmed, if so, drop the whole archive | |
352 local last = list[#list].when or datetime.parse(list[#list].attr.stamp); | |
353 if last <= to_when then | |
354 return datamanager.list_store(username, host, self.store, nil); | |
355 end | |
356 | |
350 -- luacheck: ignore 211/exact | 357 -- luacheck: ignore 211/exact |
351 local i, exact = binary_search(list, function(item) | 358 local i, exact = binary_search(list, function(item) |
352 local when = item.when or datetime.parse(item.attr.stamp); | 359 local when = item.when or datetime.parse(item.attr.stamp); |
353 return to_when - when; | 360 return to_when - when; |
354 end); | 361 end); |