From 7183e64a2e50913271cf25c7119f8bce78e0e2d7 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 9 Dec 2023 15:37:25 +0000 Subject: [PATCH] feat: peopleToSave capped at 100 due to 5mb limit --- src/background/PeopleHandler.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/background/PeopleHandler.ts b/src/background/PeopleHandler.ts index b6b85b4..ae9503b 100644 --- a/src/background/PeopleHandler.ts +++ b/src/background/PeopleHandler.ts @@ -7,6 +7,7 @@ import { debug } from '~src/misc/config'; import type { Person, ProfileResponseData, UserStats } from '~src/misc/tinderTypes'; const maxPeopleToStore = 1000; +const maxPeopleToSave = 100; export type photoInfo = { hqUrl: string; @@ -69,7 +70,7 @@ export class PeopleHandler { this.storage.get('people').then((data) => { if (!data) return; - this.people = [...this.people, ...data]; + this.handleNewPeople(data); }); } @@ -157,7 +158,11 @@ export class PeopleHandler { } async savePeople() { - await this.storage.set('people', this.people); + // storage limit of 5MB so we can't save everyone ;( + const peopleToSave = this.people + .sort((a, b) => b.addedAt - a.addedAt) + .slice(0, maxPeopleToSave); + await this.storage.set('people', peopleToSave); } async handleProfile(profile: ProfileResponseData) {