fix: Don't filter search results when a query of filter is set (#118)

Replaces #116 which filtered too broadly
pull/119/head
J M Rossy 1 month ago committed by GitHub
parent 9cbaca90b6
commit 8da2ad6106
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      src/features/messages/queries/parse.ts
  2. 20
      src/features/messages/queries/useMessageQuery.ts

@ -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(

@ -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) {
@ -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

Loading…
Cancel
Save