Store stolenData within requests - don't recalculate it every time

This commit is contained in:
Kuba Orlik 2021-11-07 11:18:53 +01:00
parent f26adda1a8
commit 9f2712e0f9
5 changed files with 25 additions and 8 deletions

View File

@ -17,10 +17,12 @@ export default class ExtendedRequest {
public requestHeaders: Request["requestHeaders"]; public requestHeaders: Request["requestHeaders"];
public origin: string; public origin: string;
public initialized = false; public initialized = false;
public stolenData: StolenDataEntry[];
async init() { async init() {
await this.cacheOrigin(); await this.cacheOrigin();
this.initialized = true; this.initialized = true;
this.stolenData = this.getAllStolenData();
} }
async cacheOrigin(): Promise<void> { async cacheOrigin(): Promise<void> {
@ -67,13 +69,13 @@ export default class ExtendedRequest {
const path = url.pathname; const path = url.pathname;
return ( return (
this.getReferer().includes(host) || this.getReferer().includes(host) ||
this.getAllStolenData().filter( this.stolenData.filter(
(entry) => entry.value.includes(host) || entry.value.includes(path) (entry) => entry.value.includes(host) || entry.value.includes(path)
).length > 0 ).length > 0
); );
} }
getAllStolenData(): StolenDataEntry[] { private getAllStolenData(): StolenDataEntry[] {
return [ return [
...this.getPathParams(), ...this.getPathParams(),
...this.getCookieData(), ...this.getCookieData(),

View File

@ -18,6 +18,7 @@ export class StolenDataEntry {
public isIAB = false; public isIAB = false;
public iab: TCModel | null = null; public iab: TCModel | null = null;
public id: number; public id: number;
public markedKeys: string[] = [];
constructor( constructor(
public request: ExtendedRequest, public request: ExtendedRequest,
@ -77,6 +78,10 @@ export class StolenDataEntry {
getParsedValue(): string | Record<string, unknown> { getParsedValue(): string | Record<string, unknown> {
return StolenDataEntry.parseValue(this.value); return StolenDataEntry.parseValue(this.value);
} }
addMarkedValue(key: string) {
this.markedKeys.push(key);
}
} }
export class MergedStolenDataEntry { export class MergedStolenDataEntry {
@ -116,6 +121,10 @@ export class MergedStolenDataEntry {
getParsedValues() { getParsedValues() {
return Array.from(new Set(this.entries.map((e) => e.getParsedValue()))); 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 { export class RequestCluster extends EventEmitter {
@ -142,7 +151,7 @@ export class RequestCluster extends EventEmitter {
cookiesOnly: boolean; cookiesOnly: boolean;
}): MergedStolenDataEntry[] { }): MergedStolenDataEntry[] {
return this.requests return this.requests
.map((request) => request.getAllStolenData()) .map((request) => request.stolenData)
.reduce((a, b) => a.concat(b), []) .reduce((a, b) => a.concat(b), [])
.filter((entry) => { .filter((entry) => {
return entry.value.length >= filter.minValueLength; return entry.value.length >= filter.minValueLength;

View File

@ -17,7 +17,7 @@ const Sidebar = () => {
const [origin, setOrigin] = useState<string | null>(null); const [origin, setOrigin] = useState<string | null>(null);
const [minValueLength, setMinValueLength] = useState<number | null>(7); const [minValueLength, setMinValueLength] = useState<number | null>(7);
const [cookiesOnly, setCookiesOnly] = useState<boolean>(false); const [cookiesOnly, setCookiesOnly] = useState<boolean>(false);
const [counter] = useEmitter(memory); const [counter, setCounter] = useEmitter(memory);
useEffect(() => { useEffect(() => {
const listener = async (data) => { const listener = async (data) => {
@ -55,6 +55,7 @@ const Sidebar = () => {
<StolenData <StolenData
origin={origin} origin={origin}
refreshToken={counter} refreshToken={counter}
refresh={() => setCounter((c) => c + 1)}
minValueLength={minValueLength} minValueLength={minValueLength}
cookiesOnly={cookiesOnly} cookiesOnly={cookiesOnly}
/> />

View File

@ -45,7 +45,7 @@ function StolenDataValue({
return <StolenDataValueTable object={value} prefixKey={prefixKey} />; return <StolenDataValueTable object={value} prefixKey={prefixKey} />;
} }
export default function StolenDataRow({ export default function StolenDataCluster({
origin, origin,
shorthost, shorthost,
minValueLength, minValueLength,

View File

@ -1,17 +1,19 @@
import React from "react"; import React from "react";
import memory from "./memory"; import memory from "./memory";
import { RequestCluster } from "./request-cluster"; import { RequestCluster } from "./request-cluster";
import StolenDataRow from "./stolen-data-row"; import StolenDataCluster from "./stolen-data-cluster";
import { getshorthost } from "./util"; import { getshorthost } from "./util";
export function StolenData({ export function StolenData({
origin, origin,
minValueLength, minValueLength,
refreshToken, refreshToken,
refresh,
cookiesOnly, cookiesOnly,
}: { }: {
origin: string; origin: string;
refreshToken: number; refreshToken: number;
refresh: () => void;
minValueLength: number; minValueLength: number;
cookiesOnly: boolean; cookiesOnly: boolean;
}) { }) {
@ -40,7 +42,10 @@ export function StolenData({
</button> </button>
<button <button
style={{ marginLeft: "1rem" }} style={{ marginLeft: "1rem" }}
onClick={() => memory.removeRequestsFor(origin)} onClick={() => {
memory.removeRequestsFor(origin);
refresh();
}}
> >
Wyczyść pamięć Wyczyść pamięć
</button> </button>
@ -49,7 +54,7 @@ export function StolenData({
.filter((cluster) => !cookiesOnly || cluster.hasCookies()) .filter((cluster) => !cookiesOnly || cluster.hasCookies())
.map((cluster) => { .map((cluster) => {
return ( return (
<StolenDataRow <StolenDataCluster
origin={origin} origin={origin}
shorthost={cluster.id} shorthost={cluster.id}
key={cluster.id + origin} key={cluster.id + origin}