Skip to content

Commit

Permalink
Remove subscriptionID property from connection metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioh8010 committed Jul 15, 2024
1 parent 3ed9856 commit 0b9614e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions lib/OnyxConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Connection = {
type ConnectionMetadata = {
id: string;
callbackID: string;
subscriptionID: number;
};

class OnyxConnectionManager {
Expand Down Expand Up @@ -102,7 +101,7 @@ class OnyxConnectionManager {
});
}

return {id: mapKey, callbackID, subscriptionID: connection.subscriptionID};
return {id: mapKey, callbackID};
}

/**
Expand Down Expand Up @@ -137,7 +136,7 @@ class OnyxConnectionManager {
this.connectionsMap.forEach((connection, connectionID) => {
OnyxUtils.disconnectFromKey(connection.subscriptionID);
connection.callbacks.forEach((_, callbackID) => {
this.removeFromEvictionBlockList({id: connectionID, callbackID, subscriptionID: connection.subscriptionID});
this.removeFromEvictionBlockList({id: connectionID, callbackID});
});
});

Expand Down
16 changes: 8 additions & 8 deletions tests/unit/OnyxConnectionManagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,33 +335,33 @@ describe('OnyxConnectionManager', () => {

connectionsMap.set('connectionID1', {subscriptionID: 0, onyxKey: ONYXKEYS.TEST_KEY, callbacks: new Map(), isConnectionMade: true});
connectionsMap.get('connectionID1')?.callbacks.set('callbackID1', () => undefined);
connectionManager.addToEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID1', subscriptionID: 0});
connectionManager.addToEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID1'});
expect(evictionBlocklist[ONYXKEYS.TEST_KEY]).toEqual(['connectionID1_callbackID1']);

connectionsMap.get('connectionID1')?.callbacks.set('callbackID2', () => undefined);
connectionManager.addToEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID2', subscriptionID: 0});
connectionManager.addToEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID2'});
expect(evictionBlocklist[ONYXKEYS.TEST_KEY]).toEqual(['connectionID1_callbackID1', 'connectionID1_callbackID2']);

connectionsMap.set('connectionID2', {subscriptionID: 1, onyxKey: `${ONYXKEYS.COLLECTION.TEST_KEY}entry1`, callbacks: new Map(), isConnectionMade: true});
connectionsMap.get('connectionID2')?.callbacks.set('callbackID3', () => undefined);
connectionManager.addToEvictionBlockList({id: 'connectionID2', callbackID: 'callbackID3', subscriptionID: 1});
connectionManager.addToEvictionBlockList({id: 'connectionID2', callbackID: 'callbackID3'});
expect(evictionBlocklist[`${ONYXKEYS.COLLECTION.TEST_KEY}entry1`]).toEqual(['connectionID2_callbackID3']);

connectionManager.removeFromEvictionBlockList({id: 'connectionID2', callbackID: 'callbackID3', subscriptionID: 1});
connectionManager.removeFromEvictionBlockList({id: 'connectionID2', callbackID: 'callbackID3'});
expect(evictionBlocklist[`${ONYXKEYS.COLLECTION.TEST_KEY}entry1`]).toBeUndefined();

// inexistent callback ID, shouldn't do anything
connectionManager.removeFromEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID1000', subscriptionID: 0});
connectionManager.removeFromEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID1000'});
expect(evictionBlocklist[ONYXKEYS.TEST_KEY]).toEqual(['connectionID1_callbackID1', 'connectionID1_callbackID2']);

connectionManager.removeFromEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID2', subscriptionID: 0});
connectionManager.removeFromEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID2'});
expect(evictionBlocklist[ONYXKEYS.TEST_KEY]).toEqual(['connectionID1_callbackID1']);

connectionManager.removeFromEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID1', subscriptionID: 0});
connectionManager.removeFromEvictionBlockList({id: 'connectionID1', callbackID: 'callbackID1'});
expect(evictionBlocklist[ONYXKEYS.TEST_KEY]).toBeUndefined();

// inexistent connection ID, shouldn't do anything
expect(() => connectionManager.removeFromEvictionBlockList({id: 'connectionID0', callbackID: 'callbackID0', subscriptionID: 0})).not.toThrow();
expect(() => connectionManager.removeFromEvictionBlockList({id: 'connectionID0', callbackID: 'callbackID0'})).not.toThrow();
});
});
});

0 comments on commit 0b9614e

Please sign in to comment.