fix: limitedmemoryadapter#remove

This commit is contained in:
MARCROCK22 2024-07-07 22:00:58 +00:00
parent 804423f2a1
commit 6b931e5661

View File

@ -93,8 +93,8 @@ export class LimitedMemoryAdapter implements Adapter {
resetOnDemand: true, resetOnDemand: true,
onDelete(k) { onDelete(k) {
const relationshipNamespace = key.split('.')[0]; const relationshipNamespace = key.split('.')[0];
const relation = self.relationships.get(relationshipNamespace); const existsRelation = self.relationships.has(relationshipNamespace);
if (relation) { if (existsRelation) {
switch (relationshipNamespace) { switch (relationshipNamespace) {
case 'guild': case 'guild':
case 'user': case 'user':
@ -182,12 +182,47 @@ export class LimitedMemoryAdapter implements Adapter {
bulkRemove(keys: string[]) { bulkRemove(keys: string[]) {
for (const i of keys) { for (const i of keys) {
this.storage.get(i.split('.')[0])?.delete(i); this.remove(i);
} }
} }
remove(key: string) { remove(key: string) {
this.storage.get(key.split('.')[0])?.delete(key); const keySplit = key.split('.');
const parentNamespace = keySplit.at(0)!;
switch (parentNamespace) {
case 'ban':
case 'member':
case 'voice_state':
{
this.storage
.get(`${parentNamespace}.${keySplit.at(1)}`)
?.delete(`${parentNamespace}.${keySplit.at(1)}.${keySplit.at(2)}`);
}
break;
case 'user':
case 'guild':
this.storage.get(parentNamespace)?.delete(`${parentNamespace}.${keySplit.at(1)}`);
break;
case 'channel':
case 'emoji':
case 'presence':
case 'role':
case 'stage_instance':
case 'sticker':
case 'thread':
case 'overwrite':
case 'message':
for (const keyStorage of this.storage.keys()) {
if (keyStorage.startsWith(parentNamespace)) {
const storage = this.storage.get(keyStorage)!;
if (storage.has(key)) {
storage.delete(key);
break;
}
}
}
break;
}
} }
flush(): void { flush(): void {
@ -207,7 +242,7 @@ export class LimitedMemoryAdapter implements Adapter {
if (!relation.has(subrelationKey)) { if (!relation.has(subrelationKey)) {
relation.set(subrelationKey, []); relation.set(subrelationKey, []);
} }
return relation!.get(subrelationKey)!; return relation.get(subrelationKey)!;
} }
bulkAddToRelationShip(data: Record<string, string[]>) { bulkAddToRelationShip(data: Record<string, string[]>) {