comparison mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 2917:cd5e6534b813

mod_storage_xmlarchive: Add additional debug logging
author Kim Alvefur <zash@zash.se>
date Fri, 09 Mar 2018 21:58:47 +0100
parents d48d4d9ccae7
children f000ba14d531
comparison
equal deleted inserted replaced
2916:b1cdcbcd1c90 2917:cd5e6534b813
62 function archive:_get_idx(username, id, dates) 62 function archive:_get_idx(username, id, dates)
63 dates = dates or self:dates(username) or empty; 63 dates = dates or self:dates(username) or empty;
64 local date = id:sub(1, 10); 64 local date = id:sub(1, 10);
65 for d = 1, #dates do 65 for d = 1, #dates do
66 if date == dates[d] then 66 if date == dates[d] then
67 module:log("debug", "Loading items from %s", dates[d]); 67 module:log("debug", "Loading index for %s", dates[d]);
68 local items = dm.list_load(username .. "@" .. dates[d], self.host, self.store) or empty; 68 local items = dm.list_load(username .. "@" .. dates[d], self.host, self.store) or empty;
69 for i = 1, #items do 69 for i = 1, #items do
70 if items[i].id == id then 70 if items[i].id == id then
71 return d, i, items; 71 return d, i, items;
72 end 72 end
152 end 152 end
153 153
154 local date_open, xmlfile; 154 local date_open, xmlfile;
155 local function read_xml(date, offset, length) 155 local function read_xml(date, offset, length)
156 if xmlfile and date ~= date_open then 156 if xmlfile and date ~= date_open then
157 module:log("debug", "Closing XML file for %s", date_open);
157 xmlfile:close(); 158 xmlfile:close();
158 xmlfile = nil; 159 xmlfile = nil;
159 end 160 end
160 if not xmlfile then 161 if not xmlfile then
161 date_open = date; 162 date_open = date;
164 xmlfile, ferr = io.open(filename); 165 xmlfile, ferr = io.open(filename);
165 if not xmlfile then 166 if not xmlfile then
166 module:log("error", "Error: %s", ferr); 167 module:log("error", "Error: %s", ferr);
167 return nil, ferr; 168 return nil, ferr;
168 end 169 end
170 module:log("debug", "Opened XML file %s", filename);
169 end 171 end
170 local pos, err = xmlfile:seek("set", offset); 172 local pos, err = xmlfile:seek("set", offset);
171 if pos ~= offset then 173 if pos ~= offset then
172 return nil, err or "seek-failed"; 174 return nil, err or "seek-failed";
173 end 175 end
177 return function () 179 return function ()
178 if limit and count >= limit then if xmlfile then xmlfile:close() end return; end 180 if limit and count >= limit then if xmlfile then xmlfile:close() end return; end
179 for d = start_day, last_day, step do 181 for d = start_day, last_day, step do
180 local date = dates[d]; 182 local date = dates[d];
181 if not items then 183 if not items then
182 module:log("debug", "Loading items from %s", date); 184 module:log("debug", "Loading index for %s", date);
183 start_day = d; 185 start_day = d;
184 items = dm.list_load(username .. "@" .. date, self.host, self.store) or empty; 186 items = dm.list_load(username .. "@" .. date, self.host, self.store) or empty;
185 if not rev then 187 if not rev then
186 first_item, last_item = 1, #items; 188 first_item, last_item = 1, #items;
187 else 189 else
267 end 269 end
268 return true; 270 return true;
269 end 271 end
270 272
271 function archive:dates(username) 273 function archive:dates(username)
274 module:log("debug", "Loading root index for %s", username);
272 local dates, err = dm.list_load(username, self.host, self.store); 275 local dates, err = dm.list_load(username, self.host, self.store);
273 if not dates then return dates, err; end 276 if not dates then return dates, err; end
274 assert(type(dates[1]) == "string" and type(dates[#dates]) == "string", 277 assert(type(dates[1]) == "string" and type(dates[#dates]) == "string",
275 "Archive does not appear to be in xmlarchive format"); 278 "Archive does not appear to be in xmlarchive format");
276 return dates; 279 return dates;