kopia lustrzana https://git.internet-czas-dzialac.pl/icd/rentgen
Store stolenData within requests - don't recalculate it every time
rodzic
f26adda1a8
commit
9f2712e0f9
|
@ -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<void> {
|
||||
|
@ -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(),
|
||||
|
|
|
@ -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<string, unknown> {
|
||||
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;
|
||||
|
|
|
@ -17,7 +17,7 @@ const Sidebar = () => {
|
|||
const [origin, setOrigin] = useState<string | null>(null);
|
||||
const [minValueLength, setMinValueLength] = useState<number | null>(7);
|
||||
const [cookiesOnly, setCookiesOnly] = useState<boolean>(false);
|
||||
const [counter] = useEmitter(memory);
|
||||
const [counter, setCounter] = useEmitter(memory);
|
||||
|
||||
useEffect(() => {
|
||||
const listener = async (data) => {
|
||||
|
@ -55,6 +55,7 @@ const Sidebar = () => {
|
|||
<StolenData
|
||||
origin={origin}
|
||||
refreshToken={counter}
|
||||
refresh={() => setCounter((c) => c + 1)}
|
||||
minValueLength={minValueLength}
|
||||
cookiesOnly={cookiesOnly}
|
||||
/>
|
||||
|
|
|
@ -45,7 +45,7 @@ function StolenDataValue({
|
|||
return <StolenDataValueTable object={value} prefixKey={prefixKey} />;
|
||||
}
|
||||
|
||||
export default function StolenDataRow({
|
||||
export default function StolenDataCluster({
|
||||
origin,
|
||||
shorthost,
|
||||
minValueLength,
|
|
@ -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({
|
|||
</button>
|
||||
<button
|
||||
style={{ marginLeft: "1rem" }}
|
||||
onClick={() => memory.removeRequestsFor(origin)}
|
||||
onClick={() => {
|
||||
memory.removeRequestsFor(origin);
|
||||
refresh();
|
||||
}}
|
||||
>
|
||||
Wyczyść pamięć
|
||||
</button>
|
||||
|
@ -49,7 +54,7 @@ export function StolenData({
|
|||
.filter((cluster) => !cookiesOnly || cluster.hasCookies())
|
||||
.map((cluster) => {
|
||||
return (
|
||||
<StolenDataRow
|
||||
<StolenDataCluster
|
||||
origin={origin}
|
||||
shorthost={cluster.id}
|
||||
key={cluster.id + origin}
|
||||
|
|
Ładowanie…
Reference in New Issue