flexmonster-mongo-connector 2.9.13 → 2.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/api/MongoAPIManager.js +1 -0
- package/build/api/MongoAPIManager.js.map +1 -1
- package/build/cache/DataManager.d.ts +5 -0
- package/build/cache/DataManager.js +12 -7
- package/build/cache/DataManager.js.map +1 -1
- package/build/cache/IDataCache.d.ts +0 -1
- package/build/cache/cacheStrategies/impl/ProbibalisticCacheStrategie.js +1 -0
- package/build/cache/cacheStrategies/impl/ProbibalisticCacheStrategie.js.map +1 -1
- package/build/cache/cacheStrategies/impl/SimpleCacheStrategie.js +1 -0
- package/build/cache/cacheStrategies/impl/SimpleCacheStrategie.js.map +1 -1
- package/build/cache/customIterators/SimpleNumericIterator.js +1 -0
- package/build/cache/customIterators/SimpleNumericIterator.js.map +1 -1
- package/build/cache/dataObject/impl/AbstractDataObject.js +1 -0
- package/build/cache/dataObject/impl/AbstractDataObject.js.map +1 -1
- package/build/cache/dataObject/impl/ArrayDataObject.js +1 -0
- package/build/cache/dataObject/impl/ArrayDataObject.js.map +1 -1
- package/build/cache/dataObject/impl/FlatRequestDataObject.js +1 -0
- package/build/cache/dataObject/impl/FlatRequestDataObject.js.map +1 -1
- package/build/cache/dataObject/impl/MapDataObject.js +1 -0
- package/build/cache/dataObject/impl/MapDataObject.js.map +1 -1
- package/build/cache/impl/LocalDataCache.d.ts +6 -4
- package/build/cache/impl/LocalDataCache.js +19 -10
- package/build/cache/impl/LocalDataCache.js.map +1 -1
- package/build/config/ConfigManager.js +1 -0
- package/build/config/ConfigManager.js.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/logging/FlexmonsterLogger.js +1 -0
- package/build/logging/FlexmonsterLogger.js.map +1 -1
- package/build/logging/LoggingManager.js +1 -0
- package/build/logging/LoggingManager.js.map +1 -1
- package/build/parsers/MongoResponseParser.js +1 -0
- package/build/parsers/MongoResponseParser.js.map +1 -1
- package/build/query/MongoQueryExecutor.d.ts +2 -2
- package/build/query/MongoQueryExecutor.js +1 -0
- package/build/query/MongoQueryExecutor.js.map +1 -1
- package/build/query/builder/FilterQueryBuilder.js +1 -0
- package/build/query/builder/FilterQueryBuilder.js.map +1 -1
- package/build/query/builder/GroupingQueryBuilder.js +1 -0
- package/build/query/builder/GroupingQueryBuilder.js.map +1 -1
- package/build/query/builder/ProjectionQueryBuilder.js +1 -0
- package/build/query/builder/ProjectionQueryBuilder.js.map +1 -1
- package/build/query/builder/QueryBuilder.js +1 -0
- package/build/query/builder/QueryBuilder.js.map +1 -1
- package/build/requests/apiRequests/RequestType.js +1 -0
- package/build/requests/apiRequests/RequestType.js.map +1 -1
- package/build/requests/apiRequests/impl/AbstractApiRequest.js +1 -0
- package/build/requests/apiRequests/impl/AbstractApiRequest.js.map +1 -1
- package/build/requests/apiRequests/impl/AggregationApiRequest.js +1 -0
- package/build/requests/apiRequests/impl/AggregationApiRequest.js.map +1 -1
- package/build/requests/apiRequests/impl/DrillThroughApiRequest.js +1 -0
- package/build/requests/apiRequests/impl/DrillThroughApiRequest.js.map +1 -1
- package/build/requests/apiRequests/impl/FlatApiRequest.js +1 -0
- package/build/requests/apiRequests/impl/FlatApiRequest.js.map +1 -1
- package/build/requests/apiRequests/impl/MembersApiRequest.js +1 -0
- package/build/requests/apiRequests/impl/MembersApiRequest.js.map +1 -1
- package/build/requests/register/Register.js +1 -0
- package/build/requests/register/Register.js.map +1 -1
- package/build/requests/register/RequestKey.js +1 -0
- package/build/requests/register/RequestKey.js.map +1 -1
- package/build/requests/requestsFactory.ts/RequestsFactory.js +1 -0
- package/build/requests/requestsFactory.ts/RequestsFactory.js.map +1 -1
- package/build/schema/APISchema.js +1 -0
- package/build/schema/APISchema.js.map +1 -1
- package/build/schema/SchemaBuilder.js +1 -0
- package/build/schema/SchemaBuilder.js.map +1 -1
- package/build/schema/SchemaValueObject.js +1 -0
- package/build/schema/SchemaValueObject.js.map +1 -1
- package/build/utils/HashGenerator.d.ts +1 -0
- package/build/utils/HashGenerator.js +19 -3
- package/build/utils/HashGenerator.js.map +1 -1
- package/build/utils/MemoryCalculator.js +1 -0
- package/build/utils/MemoryCalculator.js.map +1 -1
- package/build/utils/consts/ClientSideFieldType.js +1 -0
- package/build/utils/consts/ClientSideFieldType.js.map +1 -1
- package/build/utils/consts/ClientSideFilterQueries.js +1 -0
- package/build/utils/consts/ClientSideFilterQueries.js.map +1 -1
- package/build/utils/consts/DateParts.js +1 -0
- package/build/utils/consts/DateParts.js.map +1 -1
- package/build/utils/consts/Delimeters.js +1 -0
- package/build/utils/consts/Delimeters.js.map +1 -1
- package/build/utils/consts/LoggingMessages.js +1 -0
- package/build/utils/consts/LoggingMessages.js.map +1 -1
- package/build/utils/consts/MongoFieldType.js +1 -0
- package/build/utils/consts/MongoFieldType.js.map +1 -1
- package/build/utils/consts/MongoFilterQueries.js +1 -0
- package/build/utils/consts/MongoFilterQueries.js.map +1 -1
- package/build/utils/consts/MongoPipelineStages.js +1 -0
- package/build/utils/consts/MongoPipelineStages.js.map +1 -1
- package/build/utils/consts/SupportedAggregations.js +1 -0
- package/build/utils/consts/SupportedAggregations.js.map +1 -1
- package/package.json +3 -4
- package/src/cache/DataManager.ts +24 -8
- package/src/cache/IDataCache.ts +1 -1
- package/src/cache/impl/LocalDataCache.ts +29 -13
- package/src/parsers/MongoResponseParser.ts +4 -4
- package/src/utils/HashGenerator.ts +5 -1
package/src/cache/DataManager.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { IRequestArgument } from "../requests/apiRequests/IRequestArgument";
|
|
|
19
19
|
import { RequestFactory } from "../requests/requestsFactory.ts/RequestsFactory";
|
|
20
20
|
import { ArrayDataObject } from "./dataObject/impl/ArrayDataObject";
|
|
21
21
|
import { SimpleNumericIterator } from "./customIterators/SimpleNumericIterator";
|
|
22
|
+
import { HashGenerator } from "../utils/HashGenerator";
|
|
22
23
|
//import { CachedDataInterface } from "./dataObject/CachedDataInterface";
|
|
23
24
|
//import { AbstractDataObject } from "./dataObject/impl/AbstractDataObject";
|
|
24
25
|
|
|
@@ -26,7 +27,7 @@ export class DataManager {
|
|
|
26
27
|
|
|
27
28
|
private _queryBuilder: QueryBuilder;
|
|
28
29
|
private _queryExecutor: MongoQueryExecutor;
|
|
29
|
-
private _cacheManager: IDataCache<
|
|
30
|
+
private _cacheManager: IDataCache<CacheKeyInterface, any>;
|
|
30
31
|
private isProbabilisticCacheFlushEnabled: boolean = true;
|
|
31
32
|
private _requestsRegister: Register<string, DataIterationInterface>;
|
|
32
33
|
//private readonly CHUNK_SIZE: number = 50000;
|
|
@@ -75,13 +76,17 @@ export class DataManager {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
private async _getData(apiRequest: IApiRequest): Promise<AbstractDataObject> {
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
const cacheKey: CacheKeyInterface = {
|
|
80
|
+
databaseName: apiRequest.requestArgument.db.databaseName,
|
|
81
|
+
index: apiRequest.requestArgument.index,
|
|
82
|
+
clientQuery: apiRequest.requestArgument.clientQuery
|
|
83
|
+
};
|
|
84
|
+
let data: AbstractDataObject = this.getDataFromCache(cacheKey);
|
|
80
85
|
LoggingManager.log(`Client query: ${JSON.stringify(apiRequest.requestArgument.clientQuery)}`);
|
|
81
86
|
|
|
82
87
|
if (data === undefined) {
|
|
83
88
|
data = await apiRequest.getData(this._queryBuilder, this._queryExecutor);
|
|
84
|
-
this.setDataToCache(
|
|
89
|
+
this.setDataToCache(cacheKey, <AbstractDataObject>data);
|
|
85
90
|
|
|
86
91
|
if (ConfigManager.getInstance().currentConfig.cacheEnabled) {
|
|
87
92
|
LoggingManager.log(`Putting ${apiRequest.loggingTemplate} data to cache`);
|
|
@@ -94,14 +99,14 @@ export class DataManager {
|
|
|
94
99
|
return data;
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
private getDataFromCache(
|
|
102
|
+
private getDataFromCache(keyObject: CacheKeyInterface): AbstractDataObject {
|
|
98
103
|
if (this._cacheManager === null) return undefined;
|
|
99
|
-
return this._cacheManager.getCache(
|
|
104
|
+
return this._cacheManager.getCache(keyObject);
|
|
100
105
|
}
|
|
101
106
|
|
|
102
|
-
private setDataToCache(
|
|
107
|
+
private setDataToCache(keyObject: CacheKeyInterface, data: AbstractDataObject): void {
|
|
103
108
|
if (this._cacheManager === null) return undefined;
|
|
104
|
-
this._cacheManager.setCache(
|
|
109
|
+
this._cacheManager.setCache(keyObject, data);
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
private getCacheMemoryStatus(): string {
|
|
@@ -122,6 +127,17 @@ export class DataManager {
|
|
|
122
127
|
}
|
|
123
128
|
return dataInstance.getChunk(iterator);
|
|
124
129
|
}
|
|
130
|
+
|
|
131
|
+
// private getCacheKey(objectKey: CacheKeyInterface): string {
|
|
132
|
+
// if (objectKey == null) throw new Error("Null cache object key exception");
|
|
133
|
+
// return HashGenerator.createHashFromObject(objectKey);
|
|
134
|
+
// }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface CacheKeyInterface {
|
|
138
|
+
clientQuery: object,
|
|
139
|
+
databaseName: string,
|
|
140
|
+
index: string
|
|
125
141
|
}
|
|
126
142
|
|
|
127
143
|
export interface DataIterationInterface {
|
package/src/cache/IDataCache.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ICacheStrategie } from "./cacheStrategies/ICacheStrategie";
|
|
2
2
|
|
|
3
3
|
export interface IDataCache<KeyType, DataType> {
|
|
4
|
-
hasKey(key: KeyType): boolean;
|
|
4
|
+
//hasKey(key: KeyType): boolean;
|
|
5
5
|
getCache(key: KeyType): DataType;
|
|
6
6
|
setCache(key: KeyType, data: DataType): void;
|
|
7
7
|
clearCache(): void;
|
|
@@ -3,8 +3,10 @@ import { ICacheStrategie } from "../cacheStrategies/ICacheStrategie";
|
|
|
3
3
|
import { ConfigInterface } from "../../config/ConfigInterface";
|
|
4
4
|
import { AbstractDataObject } from "../dataObject/impl/AbstractDataObject";
|
|
5
5
|
import { DataRetrievalInterface } from "../dataObject/DataRetrievalInterface";
|
|
6
|
+
import { CacheKeyInterface } from "../DataManager";
|
|
7
|
+
import { HashGenerator } from "../../utils/HashGenerator";
|
|
6
8
|
|
|
7
|
-
export class LocalDataCache implements IDataCache<
|
|
9
|
+
export class LocalDataCache implements IDataCache<CacheKeyInterface, any> {
|
|
8
10
|
|
|
9
11
|
private _cache: Map<string, CachedDataObject> = null;
|
|
10
12
|
private timeToLive: number = 0; //TTL for data objects in minutes, default 0 means we are not going to update cache
|
|
@@ -26,14 +28,15 @@ export class LocalDataCache implements IDataCache<string, any> {
|
|
|
26
28
|
this.timeToLive = minutes;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
public hasKey(key:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
31
|
+
// public hasKey(key: CacheKeyInterface): boolean {
|
|
32
|
+
// if (key == null) throw new Error("Null key exception");
|
|
33
|
+
// return this._cache.has(key);
|
|
34
|
+
// }
|
|
33
35
|
|
|
34
|
-
public getCache(key:
|
|
36
|
+
public getCache(key: CacheKeyInterface): DataRetrievalInterface {
|
|
35
37
|
if (key == null) throw new Error("Null key exception");
|
|
36
|
-
|
|
38
|
+
const keyHash: string = this.getCacheKey(key);
|
|
39
|
+
let cachedDataObject: CachedDataObject = this._cache.get(keyHash);
|
|
37
40
|
|
|
38
41
|
if (typeof cachedDataObject !== "undefined" && this._cacheStrategie.isCacheStaled(cachedDataObject, this.timeToLive)) {
|
|
39
42
|
// console.log(">>>>>stalled", ((new Date().getTime() - cachedDataObject.timeStamp) / (1000 * 60)));
|
|
@@ -56,19 +59,26 @@ export class LocalDataCache implements IDataCache<string, any> {
|
|
|
56
59
|
// > cachedDataObject.timeStamp + this.timeToLive * 1000;
|
|
57
60
|
// }
|
|
58
61
|
|
|
59
|
-
private removeFromCache(key:
|
|
62
|
+
private removeFromCache(key: CacheKeyInterface): void {
|
|
60
63
|
if (key == null) throw new Error("Null key exception");
|
|
61
|
-
const
|
|
64
|
+
const keyHash: string = this.getCacheKey(key);
|
|
65
|
+
const cachedItem: CachedDataObject = this._cache.get(keyHash);
|
|
62
66
|
if (typeof cachedItem === "undefined") return;
|
|
63
67
|
|
|
64
|
-
this.
|
|
68
|
+
this._removeFromCache(keyHash);
|
|
65
69
|
this._currentCacheSize-= cachedItem.dataMemorySize;
|
|
66
70
|
cachedItem.data = null;
|
|
67
71
|
return;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
this._cache.
|
|
74
|
+
private _removeFromCache(keyHash: string): void {
|
|
75
|
+
this._cache.delete(keyHash);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
public setCache(key: CacheKeyInterface, data: AbstractDataObject): void {
|
|
80
|
+
const keyHash: string = this.getCacheKey(key);
|
|
81
|
+
this._cache.set(keyHash,
|
|
72
82
|
{
|
|
73
83
|
data: data,
|
|
74
84
|
timeStamp: new Date().getTime(),
|
|
@@ -101,7 +111,7 @@ export class LocalDataCache implements IDataCache<string, any> {
|
|
|
101
111
|
let garbageCollectingItem: GarbageColletingItemsInterface = null;
|
|
102
112
|
while (this._cacheSizeLimit * this._garbageCollectingCoefficient <= this._currentCacheSize) {
|
|
103
113
|
garbageCollectingItem = entriesList.shift();
|
|
104
|
-
this.
|
|
114
|
+
this._removeFromCache(garbageCollectingItem.key);
|
|
105
115
|
}
|
|
106
116
|
|
|
107
117
|
entriesList = null;
|
|
@@ -132,6 +142,12 @@ export class LocalDataCache implements IDataCache<string, any> {
|
|
|
132
142
|
this._currentCacheSize = 0;
|
|
133
143
|
}
|
|
134
144
|
|
|
145
|
+
private getCacheKey(objectKey: CacheKeyInterface): string {
|
|
146
|
+
if (objectKey == null) throw new Error("Null cache object key exception");
|
|
147
|
+
const objectKeyString: string = JSON.stringify(objectKey.clientQuery) + objectKey.databaseName + objectKey.index;
|
|
148
|
+
return HashGenerator.createHashFromString(objectKeyString);
|
|
149
|
+
}
|
|
150
|
+
|
|
135
151
|
public getCacheMemoryStatus(): string {
|
|
136
152
|
return `Current cache size: ${(this._currentCacheSize / (1024 * 1024)).toFixed(2)} MB`;
|
|
137
153
|
}
|
|
@@ -3,12 +3,12 @@ import {Delimeter} from '../utils/consts/Delimeters';
|
|
|
3
3
|
import {APISchema} from '../schema/APISchema';
|
|
4
4
|
import {IRequestField} from '../requests/apiRequests/IRequestArgument';
|
|
5
5
|
import {MongoFieldType} from '../utils/consts/MongoFieldType';
|
|
6
|
-
import { Cursor } from 'mongodb';
|
|
7
6
|
import { IQuery } from '../query/IQuery';
|
|
8
7
|
import { ArrayDataObject } from '../cache/dataObject/impl/ArrayDataObject';
|
|
9
8
|
import { FlatResultDataObject } from '../cache/dataObject/impl/FlatRequestDataObject';
|
|
10
9
|
import { MemoryCalculator, MemoryConstants } from '../utils/MemoryCalculator';
|
|
11
10
|
import { AggregationApiRequest } from '../requests/apiRequests/impl/AggregationApiRequest';
|
|
11
|
+
import { AbstractCursor } from 'mongodb';
|
|
12
12
|
|
|
13
13
|
export class MongoResponseParser {
|
|
14
14
|
|
|
@@ -62,14 +62,14 @@ export class MongoResponseParser {
|
|
|
62
62
|
public parseCalculationsFromCursor(cursor: Promise<any>, query: IQuery[], dataChunkSize: number, startDate: Date = null,
|
|
63
63
|
aggregationApiRequest: AggregationApiRequest): Promise<ArrayDataObject> {
|
|
64
64
|
return new Promise((resolve, reject) => {
|
|
65
|
-
cursor.then(async (documents:
|
|
65
|
+
cursor.then(async (documents: AbstractCursor) => {
|
|
66
66
|
const parsingResult = await this.parseAggregations(documents, query, dataChunkSize, startDate, aggregationApiRequest);
|
|
67
67
|
resolve(new ArrayDataObject(parsingResult.result, parsingResult.startDate, parsingResult.memorySize));
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
private async parseAggregations(documents:
|
|
72
|
+
private async parseAggregations(documents: AbstractCursor, queries: IQuery[], dataChunkSize: number, startDate: Date = null,
|
|
73
73
|
aggregationApiRequest: AggregationApiRequest): Promise<any> {
|
|
74
74
|
|
|
75
75
|
let parsedData: any[] = [];
|
|
@@ -227,7 +227,7 @@ export class MongoResponseParser {
|
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
private async parseDrillThroughData(documents:
|
|
230
|
+
private async parseDrillThroughData(documents: AbstractCursor, fields: IRequestField[], dataChunkSize: number): Promise<any> {
|
|
231
231
|
const result: any = {
|
|
232
232
|
"fields": [],
|
|
233
233
|
"hits": []
|
|
@@ -3,6 +3,10 @@ import * as Crypto from 'crypto';
|
|
|
3
3
|
export class HashGenerator {
|
|
4
4
|
|
|
5
5
|
public static createHashFromString(input: string): string {
|
|
6
|
-
return Crypto.createHash('
|
|
6
|
+
return Crypto.createHash('sha256').update(input).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public static createHashFromObject(object: any): string {
|
|
10
|
+
return this.createHashFromString(JSON.stringify(object));
|
|
7
11
|
}
|
|
8
12
|
}
|