comparison mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 3452:0c539092aa75

mod_storage_xmlarchive: Allow lookup of IDs that don't follow the YYYY-MM-DD-RANDOM format E.g. for converted archives where the IDs are preserved. This will be expensive.
author Kim Alvefur <zash@zash.se>
date Mon, 21 Jan 2019 19:17:49 +0100
parents 26a549513f02
children 41e1cacf3c4e
comparison
equal deleted inserted replaced
3451:7b97abf26612 3452:0c539092aa75
57 end 57 end
58 58
59 function archive:_get_idx(username, id, dates) 59 function archive:_get_idx(username, id, dates)
60 module:log("debug", "Looking for item with id %q", id); 60 module:log("debug", "Looking for item with id %q", id);
61 dates = dates or self:dates(username) or empty; 61 dates = dates or self:dates(username) or empty;
62 local date = id:sub(1, 10); 62 local date = id:match("^%d%d%d%d%-%d%d%-%d%d");
63 for d = 1, #dates do 63 for d = 1, #dates do
64 if date == dates[d] then 64 if not date or date == dates[d] then
65 module:log("debug", "Loading index for %s", dates[d]); 65 module:log("debug", "Loading index for %s", dates[d]);
66 local items = dm.list_load(username .. "@" .. dates[d], self.host, self.store) or empty; 66 local items = dm.list_load(username .. "@" .. dates[d], self.host, self.store) or empty;
67 for i = 1, #items do 67 for i = 1, #items do
68 if items[i].id == id then 68 if items[i].id == id then
69 return d, i, items; 69 return d, i, items;
70 end 70 end
71 end 71 end
72 return; -- Assuming no duplicates 72 return; -- Assuming no duplicates
73 elseif date < dates[d] then 73 elseif date and date < dates[d] then
74 return; -- List is assumed to be sorted 74 return; -- List is assumed to be sorted
75 end 75 end
76 end 76 end
77 end 77 end
78 78