@lancom/shared 0.0.415 → 0.0.416

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.
@@ -2,8 +2,14 @@ import { _get, _post, _put, _delete, _patch } from './helpers';
2
2
  import adminApi from './admin';
3
3
  import { unminifySimpleProducts } from './utils/simple-products';
4
4
  import { unminifyProduct } from './utils/product';
5
+ import { getSharePromise } from './../utils/share-promises';
6
+
7
+ const shareRequestsPromises = getSharePromise(5 * 60 * 1000);
5
8
 
6
9
  const api = {
10
+ clearAllSharePromises() {
11
+ return _post('clear-share-promises');
12
+ },
7
13
  fetchClientSettings(shop, params) {
8
14
  return _get(`shop/${shop}/client-settings`, params);
9
15
  },
@@ -71,7 +77,8 @@ const api = {
71
77
  return _get(`shop/${shop}/menus`);
72
78
  },
73
79
  fetchBanners(shop, params) {
74
- return _get(`shop/${shop}/banners`, params);
80
+ const KEY = `shop/${shop}/banners_${JSON.stringify(params || {})}`;
81
+ return shareRequestsPromises.share(KEY, () => _get(`shop/${shop}/banners`, params));
75
82
  },
76
83
  fetchProductsKits(shop, params) {
77
84
  return _get(`shop/${shop}/products-kit`, params);
@@ -86,7 +93,8 @@ const api = {
86
93
  return _get(`shop/${shop}/news/${alias}?preview=${preview}`);
87
94
  },
88
95
  fetchNewsTags(shop, params) {
89
- return _get(`shop/${shop}/news-tag`, params);
96
+ const KEY = `shop/${shop}/news-tag_${JSON.stringify(params || {})}`
97
+ return shareRequestsPromises.share(KEY, () => _get(`shop/${shop}/news-tag`, params));
90
98
  },
91
99
  fetchNewsTag(shop, alias) {
92
100
  return _get(`shop/${shop}/news-tag/${alias}`);
@@ -0,0 +1,76 @@
1
+ const MAX_PROMISES_COUNT = 1000;
2
+ const DEFAULT_SHARE_LIFETIME = 10 * 1000;
3
+
4
+ export class SharePromises {
5
+ constructor(clearSharesTimeoutDelay) {
6
+ this.promises = new Map();
7
+ this.clearSharesTimeout = null;
8
+ this.clearSharesTimeoutDelay = clearSharesTimeoutDelay || DEFAULT_SHARE_LIFETIME;
9
+ }
10
+
11
+ startClearTimeout(key) {
12
+ const promise = this.promises.get(key);
13
+ if (promise) {
14
+ clearTimeout(promise.timeout);
15
+ promise.timeout = setTimeout(() => {
16
+ this.promises.delete(key);
17
+ }, this.clearSharesTimeoutDelay);
18
+ }
19
+ }
20
+
21
+ share(keyObj, promiseFactory) {
22
+ const key = `${keyObj}`;
23
+ let promise = this.promises.get(key);
24
+ if (!promise) {
25
+ this.checkMaxPromisesCount();
26
+
27
+ promise = {
28
+ promise: promiseFactory(),
29
+ timeout: null
30
+ };
31
+
32
+ this.promises.set(key, promise);
33
+
34
+ this.startClearTimeout(key);
35
+ }
36
+
37
+ promise.promise = promise.promise.then((result) => result);
38
+
39
+ return promise.promise;
40
+ }
41
+
42
+ checkMaxPromisesCount() {
43
+ if (this.promises.size >= MAX_PROMISES_COUNT) {
44
+ this.clear();
45
+ }
46
+ }
47
+
48
+ clear() {
49
+ this.promises.forEach(promise => {
50
+ clearTimeout(promise.timeout);
51
+ });
52
+ this.promises.clear();
53
+ }
54
+
55
+ clearPromise(keyObj) {
56
+ const key = `${keyObj}`;
57
+ let promise = this.promises.get(key);
58
+ if (promise) {
59
+ clearTimeout(promise.timeout);
60
+ this.promises.delete(key);
61
+ }
62
+ }
63
+ }
64
+
65
+ const allSharePromises = [];
66
+ export function getSharePromise(timeout) {
67
+ const sharePromise = new SharePromises(timeout);
68
+ allSharePromises.push(sharePromise);
69
+ return sharePromise;
70
+ }
71
+
72
+ export function clearAllSharePromises() {
73
+ for (const sharePromise of allSharePromises) {
74
+ sharePromise.clear();
75
+ }
76
+ }
@@ -32,12 +32,6 @@
32
32
  <section class="Product__section">
33
33
  <wizard-editor />
34
34
  </section>
35
- <!-- <section class="Product__section">
36
- <product-colors-selector v-if="productDetails" />
37
- </section> -->
38
- <!-- <section class="Product__section">
39
- <product-tier-prices :product="product" />
40
- </section> -->
41
35
  <section class="Product__section">
42
36
  <product-fabric-and-size-info :product="product" />
43
37
  </section>
@@ -59,23 +53,17 @@ import RelatedProducts from '@lancom/shared/components/product/related_products/
59
53
  import Gallery from '@lancom/shared/components/product/gallery/gallery';
60
54
  import { generateProductLink } from '@lancom/shared/assets/js/utils/product';
61
55
  import ProductMainInfo from './layouts/product_main_info/product-main-info';
62
- import ProductColorsSelector from './product_colors_selector/product-colors-selector';
63
- import ProductTierPrices from './layouts/product_tier_prices/product-tier-prices';
64
56
  import ProductFabricAndSizeInfo from './layouts/product_fabric_and_size_info/product-fabric-and-size-info';
65
57
  import ProductPackaging from './layouts/product_packaging/product-packaging';
66
58
  import ProductModelMeasurements from './layouts/product_model_measurements/product-model-measurements';
67
59
  import ProductSizeTable from './layouts/product_size_table/product-size-table';
68
60
  import WizardEditor from './wizard-editor/wizard-editor.vue';
69
61
 
70
-
71
- // import ProductLabelsCustomization from './layouts/product_labels_customization/product-labels-customization';
72
62
 
73
63
  export default {
74
64
  name: 'Product',
75
65
  components: {
76
66
  ProductMainInfo,
77
- ProductColorsSelector,
78
- ProductTierPrices,
79
67
  ProductFabricAndSizeInfo,
80
68
  ProductPackaging,
81
69
  ProductModelMeasurements,
@@ -41,6 +41,12 @@ export default {
41
41
  ProductReview
42
42
  },
43
43
  mixins: [],
44
+ props: {
45
+ product: {
46
+ type: Object,
47
+ required: true
48
+ }
49
+ },
44
50
  data() {
45
51
  const reviews = this.product.reviews || [];
46
52
  const [, mainReviewId] = (this.$route.hash || '').match(/review-([a-z0-9]+)/i) || [];
@@ -56,12 +62,6 @@ export default {
56
62
  ].filter(review => !!review)
57
63
  };
58
64
  },
59
- props: {
60
- product: {
61
- type: Object,
62
- required: true
63
- }
64
- },
65
65
  computed: {
66
66
  currentReview() {
67
67
  return this.reviews[this.activeIndex];
@@ -36,15 +36,15 @@ export default {
36
36
  products: []
37
37
  };
38
38
  },
39
+ async fetch() {
40
+ const { products } = await api.fetchRelatedProducts(this.shop._id, this.product.alias, { needShuffle: true });
41
+ this.products = products.splice(0, 6);
42
+ },
39
43
  computed: {
40
44
  ...mapGetters(['shop']),
41
45
  hasProducts() {
42
46
  return this.products.length > 0;
43
47
  }
44
- },
45
- async fetch() {
46
- const { products } = await api.fetchRelatedProducts(this.shop._id, this.product.alias, { needShuffle: true });
47
- this.products = products.splice(0, 6);
48
48
  }
49
49
  };
50
50
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lancom/shared",
3
- "version": "0.0.415",
3
+ "version": "0.0.416",
4
4
  "description": "lancom common scripts",
5
5
  "author": "e.tokovenko <e.tokovenko@gmail.com>",
6
6
  "repository": {
package/store/index.js CHANGED
@@ -4,9 +4,13 @@ import { getAuthToken } from '@lancom/shared/assets/js/utils/auth';
4
4
  import { getShopCountrySettings } from '@lancom/shared/assets/js/utils/shop';
5
5
  import { MESSAGES, COUNTRIES_MESSAGES } from '@/messages';
6
6
  import { SETTINGS, COUNTRIES_SETTINGS } from '@/settings';
7
+ import { getSharePromise, clearAllSharePromises } from '@lancom/shared/assets/js/utils/share-promises';
8
+
7
9
  const cookieparser = process.server ? require('cookieparser') : undefined;
8
10
  const CLOSED_NOTIFICATION = 'lancom-closed-notification-1.0';
9
11
 
12
+ const shareShopInfo = getSharePromise(60 * 1000);
13
+
10
14
  export const state = () => ({
11
15
  googleClickId: null,
12
16
  stockCountry: null,
@@ -69,9 +73,14 @@ export const actions = {
69
73
  await commit('setShop', shop);
70
74
  }
71
75
  },
72
- async nuxtServerInit({ commit }, { req }) {
73
- const shop = await api.fetchShopByUrl(process.env.HOST_NAME);
74
- const menus = await api.fetchMenus(shop._id);
76
+ async nuxtServerInit({ commit }, { req, query }) {
77
+ if (query?.cache === 'false') {
78
+ clearAllSharePromises();
79
+ await api.clearAllSharePromises();
80
+ }
81
+
82
+ const shop = await shareShopInfo.share(process.env.HOST_NAME, () => api.fetchShopByUrl(process.env.HOST_NAME));
83
+ const menus = await shareShopInfo.share(`menus_${shop._id}`, () => api.fetchMenus(shop._id));
75
84
  commit('setMenus', menus);
76
85
  commit('setShop', shop);
77
86
  // if (req.headers.cookie) {