Skip to content

Commit

Permalink
fix: Don't filter search results when a query of filter is set (#118)
Browse files Browse the repository at this point in the history
Replaces #116 which filtered too broadly
  • Loading branch information
jmrossy authored Oct 10, 2024
1 parent 9cbaca9 commit 8da2ad6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/features/messages/queries/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export function parseMessageStubResult(
.flat()
.map((m) => parseMessageStub(multiProvider, scrapedChains, m))
.filter((m): m is MessageStub => !!m)
.sort((a, b) => b.origin.timestamp - a.origin.timestamp)
.filter((m) => Date.now() - m.origin.timestamp < 1000 * 60 * 60) // filter out messages older than 1 hour
.slice(0, 20);
.sort((a, b) => b.origin.timestamp - a.origin.timestamp);
}

export function parseMessageQueryResult(
Expand Down
20 changes: 18 additions & 2 deletions src/features/messages/queries/useMessageQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { parseMessageQueryResult, parseMessageStubResult } from './parse';

const SEARCH_AUTO_REFRESH_DELAY = 15_000; // 15s
const MSG_AUTO_REFRESH_DELAY = 10_000; // 10s
const LATEST_QUERY_LIMIT = 100;
const LATEST_QUERY_LIMIT = 90;
const SEARCH_QUERY_LIMIT = 50;

export function isValidSearchQuery(input: string, allowAddress?: boolean) {
Expand Down Expand Up @@ -63,10 +63,26 @@ export function useMessageSearchQuery(

// Parse results
const multiProvider = useMultiProvider();
const messageList = useMemo(
const unfilteredMessageList = useMemo(
() => parseMessageStubResult(multiProvider, scrapedChains, data),
[multiProvider, scrapedChains, data],
);

// Filter recent messages during DB backfilling period
// TODO remove this once backfilling is complete
const hasFilter = !!(
originChainFilter ||
destinationChainFilter ||
startTimeFilter ||
endTimeFilter
);
const messageList = useMemo(() => {
if (hasInput || hasFilter) return unfilteredMessageList;
return unfilteredMessageList
.filter((m) => Date.now() - m.origin.timestamp < 1000 * 60 * 60) // filter out messages older than 1 hour
.slice(0, 20);
}, [hasInput, hasFilter, unfilteredMessageList]);

const isMessagesFound = messageList.length > 0;

// Setup interval to re-query
Expand Down

0 comments on commit 8da2ad6

Please sign in to comment.