Skip to content

Commit aae737e

Browse files
committed
fix(search): Prevent duplicate results from search query
This is a temporary fix which adds defensive code to prevent duplicate results from being returned from the thread search query which causes N1 to enter a loop and freeze (#3001). Duplicate results from the search query likely indicate that a thread was indexed twice, which was not the case before. The cause for this is still at large.
1 parent b612c93 commit aae737e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

internal_packages/thread-search/lib/search-query-subscription.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ class SearchQuerySubscription extends MutableQuerySubscription {
4848
}
4949

5050
performLocalSearch() {
51-
let dbQuery = DatabaseStore.findAll(Thread)
51+
let dbQuery = DatabaseStore.findAll(Thread).distinct()
5252
if (this._accountIds.length === 1) {
5353
dbQuery = dbQuery.where({accountId: this._accountIds[0]})
5454
}
5555
dbQuery = dbQuery
5656
.search(this._searchQuery)
5757
.order(Thread.attributes.lastMessageReceivedTimestamp.descending())
58-
.limit(30)
58+
.limit(100)
5959

6060
dbQuery.then((results) => {
6161
if (results.length > 0) {

internal_packages/thread-search/lib/search-store.es6

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class SearchStore extends NylasStore {
5353

5454
_onQueryChanged = (query) => {
5555
this._searchQuery = query;
56+
if (this._searchQuery.length <= 1) {
57+
this.trigger()
58+
return
59+
}
5660
this._compileResults();
5761
setTimeout(() => this._rebuildResults(), 0);
5862
}

0 commit comments

Comments
 (0)