@tramvai/module-client-hints 1.68.0 → 1.70.2

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/lib/server.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { __decorate } from 'tslib';
2
- import { Module, commandLineListTokens } from '@tramvai/core';
3
- import { COMBINE_REDUCERS, REQUEST_MANAGER_TOKEN, STORE_TOKEN, CONTEXT_TOKEN, COOKIE_MANAGER_TOKEN } from '@tramvai/module-common';
2
+ import { Module, Scope, commandLineListTokens } from '@tramvai/core';
3
+ import { COMBINE_REDUCERS, CREATE_CACHE_TOKEN, REQUEST_MANAGER_TOKEN, STORE_TOKEN, CONTEXT_TOKEN, COOKIE_MANAGER_TOKEN } from '@tramvai/module-common';
4
4
  import { parse } from '@tinkoff/user-agent';
5
5
  import { createEvent, createReducer, useSelector } from '@tramvai/state';
6
6
  import pathOr from '@tinkoff/utils/object/pathOr';
@@ -104,13 +104,30 @@ ClientHintsModule = __decorate([
104
104
  Module({
105
105
  providers: [
106
106
  ...providers,
107
+ {
108
+ provide: 'userAgentLruCache',
109
+ scope: Scope.SINGLETON,
110
+ useFactory: ({ createCache }) => {
111
+ return createCache('userAgent', { max: 50 });
112
+ },
113
+ deps: {
114
+ createCache: CREATE_CACHE_TOKEN,
115
+ },
116
+ },
107
117
  {
108
118
  provide: USER_AGENT_TOKEN,
109
- useFactory: ({ requestManager }) => {
110
- return parse(requestManager.getHeader('user-agent'));
119
+ useFactory: ({ requestManager, cache }) => {
120
+ const reqUserAgent = requestManager.getHeader('user-agent');
121
+ if (cache.has(reqUserAgent)) {
122
+ return cache.get(reqUserAgent);
123
+ }
124
+ const result = parse(reqUserAgent);
125
+ cache.set(reqUserAgent, result);
126
+ return result;
111
127
  },
112
128
  deps: {
113
129
  requestManager: REQUEST_MANAGER_TOKEN,
130
+ cache: 'userAgentLruCache',
114
131
  },
115
132
  },
116
133
  {
package/lib/server.js CHANGED
@@ -112,13 +112,30 @@ exports.ClientHintsModule = tslib.__decorate([
112
112
  core.Module({
113
113
  providers: [
114
114
  ...providers,
115
+ {
116
+ provide: 'userAgentLruCache',
117
+ scope: core.Scope.SINGLETON,
118
+ useFactory: ({ createCache }) => {
119
+ return createCache('userAgent', { max: 50 });
120
+ },
121
+ deps: {
122
+ createCache: moduleCommon.CREATE_CACHE_TOKEN,
123
+ },
124
+ },
115
125
  {
116
126
  provide: USER_AGENT_TOKEN,
117
- useFactory: ({ requestManager }) => {
118
- return userAgent.parse(requestManager.getHeader('user-agent'));
127
+ useFactory: ({ requestManager, cache }) => {
128
+ const reqUserAgent = requestManager.getHeader('user-agent');
129
+ if (cache.has(reqUserAgent)) {
130
+ return cache.get(reqUserAgent);
131
+ }
132
+ const result = userAgent.parse(reqUserAgent);
133
+ cache.set(reqUserAgent, result);
134
+ return result;
119
135
  },
120
136
  deps: {
121
137
  requestManager: moduleCommon.REQUEST_MANAGER_TOKEN,
138
+ cache: 'userAgentLruCache',
122
139
  },
123
140
  },
124
141
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-client-hints",
3
- "version": "1.68.0",
3
+ "version": "1.70.2",
4
4
  "description": "",
5
5
  "main": "lib/server.js",
6
6
  "module": "lib/server.es.js",
@@ -20,14 +20,14 @@
20
20
  "build-for-publish": "true"
21
21
  },
22
22
  "dependencies": {
23
- "@tinkoff/user-agent": "0.3.256",
23
+ "@tinkoff/user-agent": "0.3.261",
24
24
  "@tinkoff/utils": "^2.1.2",
25
25
  "@tramvai/safe-strings": "0.4.3"
26
26
  },
27
27
  "peerDependencies": {
28
- "@tramvai/core": "1.68.0",
29
- "@tramvai/module-common": "1.68.0",
30
- "@tramvai/state": "1.68.0",
28
+ "@tramvai/core": "1.70.2",
29
+ "@tramvai/module-common": "1.70.2",
30
+ "@tramvai/state": "1.70.2",
31
31
  "@tinkoff/dippy": "0.7.38",
32
32
  "react": ">=16.8.0",
33
33
  "react-dom": ">=16.8.0",