aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/mod_storage_internal.lua18
-rw-r--r--plugins/mod_storage_sql.lua2
-rw-r--r--spec/core_storagemanager_spec.lua38
3 files changed, 47 insertions, 11 deletions
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua
index 1332ae75..d5ef7112 100644
--- a/plugins/mod_storage_internal.lua
+++ b/plugins/mod_storage_internal.lua
@@ -205,12 +205,11 @@ function archive:find(username, query)
return query.start - when;
end);
i = wi - 1;
- else
- iter = it.filter(function(item)
- local when = item.when or datetime.parse(item.attr.stamp);
- return when >= query.start;
- end, iter);
end
+ iter = it.filter(function(item)
+ local when = item.when or datetime.parse(item.attr.stamp);
+ return when >= query.start;
+ end, iter);
end
if query["end"] then
if query.reverse then
@@ -221,12 +220,11 @@ function archive:find(username, query)
if wi then
i = wi + 1;
end
- else
- iter = it.filter(function(item)
- local when = item.when or datetime.parse(item.attr.stamp);
- return when <= query["end"];
- end, iter);
end
+ iter = it.filter(function(item)
+ local when = item.when or datetime.parse(item.attr.stamp);
+ return when <= query["end"];
+ end, iter);
end
if query.after then
local found = false;
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index e7b06f31..6d9af68a 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -883,7 +883,7 @@ local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore
indices[row[1]] = true;
end
elseif params.driver == "PostgreSQL" then
- for row in engine:select [[SELECT "indexname" FROM "pg_indexes" WHERE "tablename"='prosody' AND "indexname"='prosody_index';]] do
+ for row in engine:select [[SELECT "indexname" FROM "pg_indexes" WHERE "tablename"='prosody';]] do
indices[row[1]] = true;
end
end
diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua
index 32a8d6f0..a6857d0c 100644
--- a/spec/core_storagemanager_spec.lua
+++ b/spec/core_storagemanager_spec.lua
@@ -436,6 +436,44 @@ describe("storagemanager", function ()
assert.equal(#test_data - 3, count);
end);
+ it("by time (start before first item)", function ()
+ -- luacheck: ignore 211/err
+ local data, err = archive:find("user", {
+ ["start"] = test_time-5;
+ });
+ assert.truthy(data);
+ local count = 0;
+ for id, item, when in data do
+ count = count + 1;
+ assert.truthy(id);
+ assert(st.is_stanza(item));
+ assert.equal("test", item.name);
+ assert.equal("urn:example:foo", item.attr.xmlns);
+ assert.equal(2, #item.tags);
+ assert(when >= test_time-5, ("%d >= %d"):format(when, test_time-5));
+ end
+ assert.equal(#test_data, count);
+ end);
+
+ it("by time (start after last item)", function ()
+ -- luacheck: ignore 211/err
+ local data, err = archive:find("user", {
+ ["start"] = test_time+5;
+ });
+ assert.truthy(data);
+ local count = 0;
+ for id, item, when in data do
+ count = count + 1;
+ assert.truthy(id);
+ assert(st.is_stanza(item));
+ assert.equal("test", item.name);
+ assert.equal("urn:example:foo", item.attr.xmlns);
+ assert.equal(2, #item.tags);
+ assert(when >= test_time+5, ("%d >= %d"):format(when, test_time+5));
+ end
+ assert.equal(0, count);
+ end);
+
it("by time (start+end)", function ()
-- luacheck: ignore 211/err
local data, err = archive:find("user", {