Skip to content

Commit

Permalink
Virtualize search results - only render what's visible
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Aug 21, 2019
1 parent 9d4f2af commit 6292019
Show file tree
Hide file tree
Showing 19 changed files with 1,578 additions and 383 deletions.
68 changes: 66 additions & 2 deletions app/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,69 @@ async function updateToSchemaVersion17(currentVersion, instance) {
}
}

async function updateToSchemaVersion18(currentVersion, instance) {
if (currentVersion >= 18) {
return;
}

console.log('updateToSchemaVersion18: starting...');
await instance.run('BEGIN TRANSACTION;');

try {
// Delete and rebuild full-text search index to capture everything

await instance.run('DELETE FROM messages_fts;');
await instance.run(
"INSERT INTO messages_fts(messages_fts) VALUES('rebuild');"
);

await instance.run(`
INSERT INTO messages_fts(id, body)
SELECT id, body FROM messages WHERE isViewOnce IS NULL OR isViewOnce != 1;
`);

// Fixing full-text triggers

await instance.run('DROP TRIGGER messages_on_insert;');
await instance.run('DROP TRIGGER messages_on_update;');

await instance.run(`
CREATE TRIGGER messages_on_insert AFTER INSERT ON messages
WHEN new.isViewOnce IS NULL OR new.isViewOnce != 1
BEGIN
INSERT INTO messages_fts (
id,
body
) VALUES (
new.id,
new.body
);
END;
`);
await instance.run(`
CREATE TRIGGER messages_on_update AFTER UPDATE ON messages
WHEN new.isViewOnce IS NULL OR new.isViewOnce != 1
BEGIN
DELETE FROM messages_fts WHERE id = old.id;
INSERT INTO messages_fts(
id,
body
) VALUES (
new.id,
new.body
);
END;
`);

await instance.run('PRAGMA schema_version = 18;');
await instance.run('COMMIT TRANSACTION;');
console.log('updateToSchemaVersion18: success!');
} catch (error) {
await instance.run('ROLLBACK;');
throw error;
}
}

const SCHEMA_VERSIONS = [
updateToSchemaVersion1,
updateToSchemaVersion2,
Expand All @@ -1035,6 +1098,7 @@ const SCHEMA_VERSIONS = [
updateToSchemaVersion15,
updateToSchemaVersion16,
updateToSchemaVersion17,
updateToSchemaVersion18,
];

async function updateSchema(instance) {
Expand Down Expand Up @@ -1552,7 +1616,7 @@ async function searchConversations(query, { limit } = {}) {
$id: `%${query}%`,
$name: `%${query}%`,
$profileName: `%${query}%`,
$limit: limit || 50,
$limit: limit || 100,
}
);

Expand All @@ -1572,7 +1636,7 @@ async function searchMessages(query, { limit } = {}) {
LIMIT $limit;`,
{
$query: query,
$limit: limit || 100,
$limit: limit || 500,
}
);

Expand Down
1 change: 0 additions & 1 deletion stylesheets/_conversation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
position: relative;
max-width: 100%;
margin: 0;
margin-bottom: 10px;

.timeline-wrapper {
-webkit-padding-start: 0px;
Expand Down
4 changes: 2 additions & 2 deletions stylesheets/_modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3125,8 +3125,8 @@
// Module: Search Results

.module-search-results {
overflow-y: scroll;
max-height: 100%;
overflow: hidden;
flex-grow: 1;
}

.module-search-results__conversations-header {
Expand Down
2 changes: 1 addition & 1 deletion stylesheets/_theme_dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ body.dark-theme {
}

.module-message-search-result__body {
color: $color-gray-05;
color: $color-gray-15;
}

// Module: Left Pane
Expand Down

0 comments on commit 6292019

Please sign in to comment.