Merge pull request #4345 from itsjohncs/small-db-cleanups
Small cleanup of messageStorage/sqlite.
This commit is contained in:
commit
0381cd11bf
@ -124,7 +124,7 @@ export default {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.search.results.slice().reverse();
|
||||
return this.search.results;
|
||||
},
|
||||
chan() {
|
||||
const chanId = parseInt(this.$route.params.id, 10);
|
||||
|
@ -236,7 +236,7 @@ class MessageStorage {
|
||||
target: query.channelName,
|
||||
networkUuid: query.networkUuid,
|
||||
offset: query.offset,
|
||||
results: parseSearchRowsToMessages(query.offset, rows),
|
||||
results: parseSearchRowsToMessages(query.offset, rows).reverse(),
|
||||
};
|
||||
resolve(response);
|
||||
}
|
||||
|
@ -37,10 +37,9 @@ describe("SQLite Message Storage", function () {
|
||||
fs.rmdir(path.join(Helper.getHomePath(), "logs"), done);
|
||||
});
|
||||
|
||||
it("should resolve an empty array when disabled", function (done) {
|
||||
store.getMessages(null, null).then((messages) => {
|
||||
it("should resolve an empty array when disabled", function () {
|
||||
return store.getMessages(null, null).then((messages) => {
|
||||
expect(messages).to.be.empty;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@ -54,7 +53,6 @@ describe("SQLite Message Storage", function () {
|
||||
});
|
||||
|
||||
it("should create tables", function (done) {
|
||||
store.database.serialize(() =>
|
||||
store.database.all(
|
||||
"SELECT name, tbl_name, sql FROM sqlite_master WHERE type = 'table'",
|
||||
(err, row) => {
|
||||
@ -76,12 +74,10 @@ describe("SQLite Message Storage", function () {
|
||||
|
||||
done();
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should insert schema version to options table", function (done) {
|
||||
store.database.serialize(() =>
|
||||
store.database.get(
|
||||
"SELECT value FROM options WHERE name = 'schema_version'",
|
||||
(err, row) => {
|
||||
@ -93,12 +89,10 @@ describe("SQLite Message Storage", function () {
|
||||
|
||||
done();
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should store a message", function (done) {
|
||||
store.database.serialize(() => {
|
||||
it("should store a message", function () {
|
||||
store.index(
|
||||
{
|
||||
uuid: "this-is-a-network-guid",
|
||||
@ -111,14 +105,10 @@ describe("SQLite Message Storage", function () {
|
||||
text: "Hello from sqlite world!",
|
||||
})
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should retrieve previously stored message", function (done) {
|
||||
store.database.serialize(() =>
|
||||
store
|
||||
it("should retrieve previously stored message", function () {
|
||||
return store
|
||||
.getMessages(
|
||||
{
|
||||
uuid: "this-is-a-network-guid",
|
||||
@ -135,10 +125,62 @@ describe("SQLite Message Storage", function () {
|
||||
expect(msg.text).to.equal("Hello from sqlite world!");
|
||||
expect(msg.type).to.equal(Msg.Type.MESSAGE);
|
||||
expect(msg.time.getTime()).to.equal(123456789);
|
||||
});
|
||||
});
|
||||
|
||||
done();
|
||||
it("should retrieve latest LIMIT messages in order", function () {
|
||||
const originalMaxHistory = Helper.config.maxHistory;
|
||||
|
||||
try {
|
||||
Helper.config.maxHistory = 2;
|
||||
|
||||
for (let i = 0; i < 200; ++i) {
|
||||
store.index(
|
||||
{uuid: "retrieval-order-test-network"},
|
||||
{name: "#channel"},
|
||||
new Msg({
|
||||
time: 123456789 + i,
|
||||
text: `msg ${i}`,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return store
|
||||
.getMessages({uuid: "retrieval-order-test-network"}, {name: "#channel"})
|
||||
.then((messages) => {
|
||||
expect(messages).to.have.lengthOf(2);
|
||||
expect(messages.map((i) => i.text)).to.deep.equal(["msg 198", "msg 199"]);
|
||||
});
|
||||
} finally {
|
||||
Helper.config.maxHistory = originalMaxHistory;
|
||||
}
|
||||
});
|
||||
|
||||
it("should search messages", function () {
|
||||
const originalMaxHistory = Helper.config.maxHistory;
|
||||
|
||||
try {
|
||||
Helper.config.maxHistory = 2;
|
||||
|
||||
return store
|
||||
.search({
|
||||
searchTerm: "msg",
|
||||
networkUuid: "retrieval-order-test-network",
|
||||
})
|
||||
.then((messages) => {
|
||||
expect(messages.results).to.have.lengthOf(100);
|
||||
|
||||
const expectedMessages = [];
|
||||
|
||||
for (let i = 100; i < 200; ++i) {
|
||||
expectedMessages.push(`msg ${i}`);
|
||||
}
|
||||
|
||||
expect(messages.results.map((i) => i.text)).to.deep.equal(expectedMessages);
|
||||
});
|
||||
} finally {
|
||||
Helper.config.maxHistory = originalMaxHistory;
|
||||
}
|
||||
});
|
||||
|
||||
it("should close database", function (done) {
|
||||
|
Loading…
Reference in New Issue
Block a user