Skip to content

Commit 3b5ddd8

Browse files
committed
feat: optimize keys serialization function
1 parent 8f94626 commit 3b5ddd8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

packages/store/node-server-sdk-redis/src/RedisCore.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,21 @@ export default class RedisCore implements interfaces.PersistentDataStore {
112112
}
113113

114114
#prepareArray(values: Record<string, string>) {
115-
const results: interfaces.KeyedItem<string, interfaces.SerializedItemDescriptor>[] = [];
116-
Object.keys(values).forEach((key) => {
117-
const value = values[key];
118-
// When getting we do not populate version and deleted.
119-
// The SDK will have to deserialize to access these values.
120-
results.push({ key, item: { version: 0, deleted: false, serializedItem: value } });
121-
});
122-
return results;
115+
const keys = Object.keys(values);
116+
const results: interfaces.KeyedItem<string, interfaces.SerializedItemDescriptor>[] = new Array(
117+
keys.length,
118+
);
119+
return keys.reduce((acc, key, index) => {
120+
acc[index] = {
121+
key,
122+
item: {
123+
version: 0,
124+
deleted: false,
125+
serializedItem: values[key],
126+
},
127+
};
128+
return acc;
129+
}, results);
123130
}
124131

125132
#useItemsFromCodefresh(

0 commit comments

Comments
 (0)