From 9f2712e0f9ffdbb8847b3d6236259ee2431d838a Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Sun, 7 Nov 2021 11:18:53 +0100 Subject: [PATCH] Store stolenData within requests - don't recalculate it every time --- extended-request.ts | 6 ++++-- request-cluster.ts | 11 ++++++++++- sidebar.tsx | 3 ++- stolen-data-row.tsx => stolen-data-cluster.tsx | 2 +- stolen-data.tsx | 11 ++++++++--- 5 files changed, 25 insertions(+), 8 deletions(-) rename stolen-data-row.tsx => stolen-data-cluster.tsx (98%) diff --git a/extended-request.ts b/extended-request.ts index 1125fa3..0f70832 100644 --- a/extended-request.ts +++ b/extended-request.ts @@ -17,10 +17,12 @@ export default class ExtendedRequest { public requestHeaders: Request["requestHeaders"]; public origin: string; public initialized = false; + public stolenData: StolenDataEntry[]; async init() { await this.cacheOrigin(); this.initialized = true; + this.stolenData = this.getAllStolenData(); } async cacheOrigin(): Promise { @@ -67,13 +69,13 @@ export default class ExtendedRequest { const path = url.pathname; return ( this.getReferer().includes(host) || - this.getAllStolenData().filter( + this.stolenData.filter( (entry) => entry.value.includes(host) || entry.value.includes(path) ).length > 0 ); } - getAllStolenData(): StolenDataEntry[] { + private getAllStolenData(): StolenDataEntry[] { return [ ...this.getPathParams(), ...this.getCookieData(), diff --git a/request-cluster.ts b/request-cluster.ts index 902622e..d5d751f 100644 --- a/request-cluster.ts +++ b/request-cluster.ts @@ -18,6 +18,7 @@ export class StolenDataEntry { public isIAB = false; public iab: TCModel | null = null; public id: number; + public markedKeys: string[] = []; constructor( public request: ExtendedRequest, @@ -77,6 +78,10 @@ export class StolenDataEntry { getParsedValue(): string | Record { return StolenDataEntry.parseValue(this.value); } + + addMarkedValue(key: string) { + this.markedKeys.push(key); + } } export class MergedStolenDataEntry { @@ -116,6 +121,10 @@ export class MergedStolenDataEntry { getParsedValues() { return Array.from(new Set(this.entries.map((e) => e.getParsedValue()))); } + + addMarkedValue(key: string) { + this.entries.forEach((entry) => entry.addMarkedValue(key)); + } } export class RequestCluster extends EventEmitter { @@ -142,7 +151,7 @@ export class RequestCluster extends EventEmitter { cookiesOnly: boolean; }): MergedStolenDataEntry[] { return this.requests - .map((request) => request.getAllStolenData()) + .map((request) => request.stolenData) .reduce((a, b) => a.concat(b), []) .filter((entry) => { return entry.value.length >= filter.minValueLength; diff --git a/sidebar.tsx b/sidebar.tsx index 749ff52..d7f96f3 100644 --- a/sidebar.tsx +++ b/sidebar.tsx @@ -17,7 +17,7 @@ const Sidebar = () => { const [origin, setOrigin] = useState(null); const [minValueLength, setMinValueLength] = useState(7); const [cookiesOnly, setCookiesOnly] = useState(false); - const [counter] = useEmitter(memory); + const [counter, setCounter] = useEmitter(memory); useEffect(() => { const listener = async (data) => { @@ -55,6 +55,7 @@ const Sidebar = () => { setCounter((c) => c + 1)} minValueLength={minValueLength} cookiesOnly={cookiesOnly} /> diff --git a/stolen-data-row.tsx b/stolen-data-cluster.tsx similarity index 98% rename from stolen-data-row.tsx rename to stolen-data-cluster.tsx index a92ec35..5b18878 100644 --- a/stolen-data-row.tsx +++ b/stolen-data-cluster.tsx @@ -45,7 +45,7 @@ function StolenDataValue({ return ; } -export default function StolenDataRow({ +export default function StolenDataCluster({ origin, shorthost, minValueLength, diff --git a/stolen-data.tsx b/stolen-data.tsx index 544fbec..9334c79 100644 --- a/stolen-data.tsx +++ b/stolen-data.tsx @@ -1,17 +1,19 @@ import React from "react"; import memory from "./memory"; import { RequestCluster } from "./request-cluster"; -import StolenDataRow from "./stolen-data-row"; +import StolenDataCluster from "./stolen-data-cluster"; import { getshorthost } from "./util"; export function StolenData({ origin, minValueLength, refreshToken, + refresh, cookiesOnly, }: { origin: string; refreshToken: number; + refresh: () => void; minValueLength: number; cookiesOnly: boolean; }) { @@ -40,7 +42,10 @@ export function StolenData({ @@ -49,7 +54,7 @@ export function StolenData({ .filter((cluster) => !cookiesOnly || cluster.hasCookies()) .map((cluster) => { return ( -