Skip to content

Commit

Permalink
signature hashing optimizations++, awaiting for official release, do …
Browse files Browse the repository at this point in the history
…not publish this
  • Loading branch information
Mikhus committed Nov 15, 2018
1 parent e55cce1 commit abef85e
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -42,7 +42,7 @@
"@types/acorn": "^4.0.3",
"@types/node": "^10.9.4",
"acorn": "^5.7.3",
"murmurhash-native": "^3.2.4",
"murmurhash-native": "royaltm/node-murmurhash-native",
"node-machine-id": "^1.1.10",
"reflect-metadata": "^0.1.12",
"typescript": "^3.0.3"
Expand Down
2 changes: 1 addition & 1 deletion src/IMQCache.ts
Expand Up @@ -80,7 +80,7 @@ export class IMQCache {

let opts = self.options[name] || {};

self.options[name] = Object.assign(opts, options);
self.options[name] = { ...opts, ...options };

return self;
}
Expand Down
14 changes: 5 additions & 9 deletions src/IMQClient.ts
Expand Up @@ -87,11 +87,7 @@ export abstract class IMQClient extends EventEmitter {
'be instantiated directly!');
}

this.options = Object.assign({},
DEFAULT_IMQ_CLIENT_OPTIONS,
options || /* istanbul ignore next */ {}
);

this.options = { ...DEFAULT_IMQ_CLIENT_OPTIONS, ...options };
this.id = pid(baseName);
this.logger = this.options.logger || /* istanbul ignore next */ console;
this.name = `${baseName}-${osUuid()}-${this.id}:client`;
Expand Down Expand Up @@ -225,10 +221,10 @@ export abstract class IMQClient extends EventEmitter {
name: string,
options?: Partial<IMQClientOptions>
): Promise<any> {
const clientOptions: IMQClientOptions = Object.assign({},
DEFAULT_IMQ_CLIENT_OPTIONS,
options
);
const clientOptions: IMQClientOptions = {
...DEFAULT_IMQ_CLIENT_OPTIONS,
...options,
};

return await generator(name, clientOptions);
}
Expand Down
34 changes: 16 additions & 18 deletions src/IMQRPCOptions.ts
Expand Up @@ -34,27 +34,25 @@ export interface IMQClientOptions extends IMQOptions {
*
* @type {IMQServiceOptions}
*/
export const DEFAULT_IMQ_SERVICE_OPTIONS: IMQServiceOptions = Object.assign({},
DEFAULT_IMQ_OPTIONS, {
cleanup: true,
cleanupFilter: '*:client',
multiProcess: false,
childrenPerCore: 1,
},
);
export const DEFAULT_IMQ_SERVICE_OPTIONS: IMQServiceOptions = {
...DEFAULT_IMQ_OPTIONS,
cleanup: true,
cleanupFilter: '*:client',
multiProcess: false,
childrenPerCore: 1,
};

/**
* Default client options
*
* @type {IMQClientOptions}
*/
export const DEFAULT_IMQ_CLIENT_OPTIONS: IMQClientOptions = Object.assign({},
DEFAULT_IMQ_OPTIONS, {
cleanup: true,
cleanupFilter: '*:client',
path: './src/clients',
compile: true,
timeout: 30000,
write: true,
},
);
export const DEFAULT_IMQ_CLIENT_OPTIONS: IMQClientOptions = {
...DEFAULT_IMQ_OPTIONS,
cleanup: true,
cleanupFilter: '*:client',
path: './src/clients',
compile: true,
timeout: 30000,
write: true,
};
10 changes: 2 additions & 8 deletions src/IMQService.ts
Expand Up @@ -113,14 +113,8 @@ export abstract class IMQService {
'be instantiated directly!');
}

this.options = Object.assign({},
DEFAULT_IMQ_SERVICE_OPTIONS,
options || {}
);

this.logger = this.options.logger ||
// istanbul ignore next
console;
this.options = { ...DEFAULT_IMQ_SERVICE_OPTIONS, ...options };
this.logger = this.options.logger || /* istanbul ignore next */ console;
this.imq = IMQ.create(this.name, this.options);

this.handleRequest = this.handleRequest.bind(this);
Expand Down
19 changes: 9 additions & 10 deletions src/cache/RedisCache.ts
Expand Up @@ -29,10 +29,10 @@ export interface IRedisCacheOptions extends Partial<IMQOptions> {
conn?: IRedisClient
}

export const DEFAULT_REDIS_CACHE_OPTIONS = Object.assign(
{}, DEFAULT_IMQ_OPTIONS, {
prefix: 'imq-cache'
});
export const DEFAULT_REDIS_CACHE_OPTIONS = {
...DEFAULT_IMQ_OPTIONS,
prefix: 'imq-cache',
};

/**
* Class RedisCache. Implements cache engine over redis.
Expand All @@ -47,15 +47,14 @@ export class RedisCache implements ICache {
/**
* Initializes cache instance
*
* @param {IRedisCacheOptions} options
* @param {IRedisCacheOptions} [options]
* @returns {Promise<RedisCache>}
*/
public async init(options?: IRedisCacheOptions): Promise<RedisCache> {
this.options = Object.assign(
{}, DEFAULT_REDIS_CACHE_OPTIONS, options ||
// istanbul ignore next
{}
);
this.options = {
...DEFAULT_REDIS_CACHE_OPTIONS,
...options,
};

this.logger = this.options.logger ||
// istanbul ignore next
Expand Down
12 changes: 6 additions & 6 deletions src/decorators/cache.ts
Expand Up @@ -30,18 +30,18 @@ export interface CacheDecorator {

// codebeat:disable[BLOCK_NESTING]
export const cache: CacheDecorator = function(options?: CacheDecoratorOptions) {
const cacheOptions: CacheDecoratorOptions =
Object.assign({}, cache.globalOptions, options || {});
const cacheOptions: CacheDecoratorOptions = {
...cache.globalOptions,
...options,
};
let Adapter: any = cacheOptions.adapter || RedisCache;

return function(
target: any,
methodName: string | symbol,
descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
) {
const original = descriptor.value ||
// istanbul ignore next
(() => {});
const original: (...args: any[]) => any = descriptor.value as any;

descriptor.value = async function(...args: any[]) {
const context: any = this;
Expand All @@ -66,7 +66,7 @@ export const cache: CacheDecorator = function(options?: CacheDecoratorOptions) {
(context.imq && context.imq.logger);

if (logger) {
opts = Object.assign(opts || {}, { logger });
opts = { ...opts, logger };
}

await IMQCache.register(Adapter, opts).init();
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/signature.ts
Expand Up @@ -15,7 +15,7 @@
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
const hash = require('murmurhash-native');
import { murmurHash64 } from 'murmurhash-native';

/**
* Constructs and returns hash string for a given set of className, methodName
Expand All @@ -31,7 +31,7 @@ export function signature(
methodName: string | symbol,
args: any[]
): string {
return hash.murmurHash128x64(JSON.stringify([
return murmurHash64(JSON.stringify([
className, methodName, args
]));
}
2 changes: 1 addition & 1 deletion test/helpers/signature.ts
Expand Up @@ -25,7 +25,7 @@ describe('helpers/signature()', () => {
});

it('should return hash string', () => {
expect(/^[0-9a-f]{32}$/.test(signature('A', 'a', []))).to.be.true;
expect(/^[0-9a-f]{16,32}$/.test(signature('A', 'a', []))).to.be.true;
});

it('should return same hash string for the same arguments bypassed', () => {
Expand Down

0 comments on commit abef85e

Please sign in to comment.