Skip to content

Commit 30692c6

Browse files
committed
Fixed an issue where storage items would be saved twice and where an item wouldn't be returned by the full key name.
1 parent 54c828a commit 30692c6

8 files changed

+35
-15
lines changed

Diff for: dist/exceptionless.js

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/exceptionless.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/exceptionless.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/exceptionless.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/exceptionless.node.js

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/exceptionless.node.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/storage/InMemoryStorage-spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ describe('InMemoryStorage', () => {
1818
expect(storage.getList(key + '1').length).toBe(1);
1919
});
2020

21+
it('should save once', () => {
22+
var storage = new InMemoryStorage<number>();
23+
storage.save('one', 1);
24+
expect(storage.getList().length).toBe(1);
25+
storage.save('one', 1);
26+
expect(storage.getList().length).toBe(1);
27+
});
28+
29+
it('should get by key', () => {
30+
var storage = new InMemoryStorage<any>();
31+
storage.save('ex-server-settings.json-version', 1);
32+
storage.save('ex-server-settings.json', { exist: true });
33+
expect(storage.getList().length).toBe(2);
34+
expect(storage.get('ex-server-settings.json-version')).toBe(1);
35+
expect(storage.get('ex-server-settings.json')).toEqual({ exist: true });
36+
});
37+
2138
it('should get saved events', () => {
2239
var storage = new InMemoryStorage<IEvent>();
2340
var key = 'ex-q-';

Diff for: src/storage/InMemoryStorage.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class InMemoryStorage<T> implements IStorage<T> {
1515
return false;
1616
}
1717

18+
this.remove(path);
1819
if (this._items.push({ created: new Date().getTime(), path: path, value: value }) > this._maxItems) {
1920
this._items.shift();
2021
}
@@ -23,7 +24,7 @@ export class InMemoryStorage<T> implements IStorage<T> {
2324
}
2425

2526
public get(path:string):T {
26-
var item:IStorageItem<T> = path ? this.getList(path, 1)[0] : null;
27+
var item:IStorageItem<T> = path ? this.getList(`^${path}$`, 1)[0] : null;
2728
return item ? item.value : null;
2829
}
2930

@@ -50,7 +51,7 @@ export class InMemoryStorage<T> implements IStorage<T> {
5051

5152
public remove(path:string):void {
5253
if (path) {
53-
var item = this.getList(path, 1)[0];
54+
var item = this.getList(`^${path}$`, 1)[0];
5455
if (item) {
5556
this._items.splice(this._items.indexOf(item), 1);
5657
}

0 commit comments

Comments
 (0)