# HG changeset patch # User shinysky # Date 1280394323 -28800 # Node ID 7fe326037070a094775a069803817c761c73ba4d # Parent 95d4d53f09a103a9ff08f64dbeed80f5b70922ed mod_archive: exit for loop as soon as possible. diff -r 95d4d53f09a1 -r 7fe326037070 mod_archive/mod_archive.lua --- a/mod_archive/mod_archive.lua Thu Jul 29 14:36:41 2010 +0800 +++ b/mod_archive/mod_archive.lua Thu Jul 29 17:05:23 2010 +0800 @@ -106,11 +106,7 @@ -- TODO assuming the collection list are in REVERSE chronological order for k, v in ipairs(data) do local collection = st.deserialize(v); - if thread and collection.attr["thread"] == thread:get_text() - or - not thread - and collection.attr["with"] == with - and os.difftime(utc_secs, date_parse(collection.attr["start"])) < 14400 then + local do_save = function() local dt = 1; for i = #collection, 1, -1 do local s = collection[i].attr["utc_secs"]; @@ -125,7 +121,19 @@ collection.attr["access"] = utc_datetime; data[k] = collection; dm.list_store(node, host, ARCHIVE_DIR, st.preserialize(data)); - return; + end + if thread then + if collection.attr["thread"] == thread:get_text() then + do_save(); + return; + end + else + local dt = os.difftime(utc_secs, date_parse(collection.attr["start"])); + if dt >= 14400 then break end + if collection.attr["with"] == with then + do_save(); + return; + end end end end @@ -330,7 +338,7 @@ local elem = stanza.tags[1]; local node, host = origin.username, origin.host; local data = load_prefs(node, host); - if not data then + if not data then -- TODO create new pref? return false; end local setting = data:child_with_name(elem.name)