From 6c3562b1206796172b79aaeef62cd60def88d853 Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Sun, 11 Mar 2018 21:08:47 +0300 Subject: [PATCH 1/3] remove useless styles from list-comments component --- web/app/components/list-comments/list-comments.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/web/app/components/list-comments/list-comments.scss b/web/app/components/list-comments/list-comments.scss index e4f0b120..ce27387e 100644 --- a/web/app/components/list-comments/list-comments.scss +++ b/web/app/components/list-comments/list-comments.scss @@ -1,4 +1,3 @@ .list-comments { - position: relative; font-family: 'PT Sans', Helvetica, Arial, sans-serif; } From f711f3151fe5e76432d9d55f8d0a3ba50c4ca45f Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Sun, 11 Mar 2018 21:23:52 +0300 Subject: [PATCH 2/3] add temp solution for extracting all styles to one bundle --- web/app/remark.js | 1 + web/webpack.config.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/web/app/remark.js b/web/app/remark.js index 97009fae..0b28667a 100644 --- a/web/app/remark.js +++ b/web/app/remark.js @@ -3,6 +3,7 @@ import 'common/polyfills'; // TODO: check it import { h, render } from 'preact'; import Root from './components/root'; +import ListComments from './components/list-comments'; // TODO: temp solution for extracting styles import { NODE_ID } from './common/constants'; diff --git a/web/webpack.config.js b/web/webpack.config.js index 8ee7bd5b..48857e75 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -38,10 +38,10 @@ const commonStyleLoaders = [ module.exports = { context: __dirname, entry: { - remark: './app/remark', embed: './app/embed', counter: './app/counter', 'last-comments': './app/last-comments', + remark: './app/remark', }, output: { path: publicFolder, From dd1c6332f798a00ce1f8ced4e40b681e0b5b8938 Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Sun, 11 Mar 2018 21:44:10 +0300 Subject: [PATCH 3/3] rewrite counter to batch request --- web/app/common/api.js | 5 ++++- web/app/counter.js | 16 ++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/web/app/common/api.js b/web/app/common/api.js index 59dc06de..46cdb174 100644 --- a/web/app/common/api.js +++ b/web/app/common/api.js @@ -12,7 +12,10 @@ export const find = ({ url }) => fetcher.get(`/find?url=${url}&sort=-score&forma export const last = ({ siteId, max }) => fetcher.get(`/last/${max}?site=${siteId}`); -export const count = ({ url, siteId }) => fetcher.get(`/count?url=${url}&site=${siteId}`); +export const count = ({ urls, siteId }) => fetcher.post({ + url: `/count?site=${siteId}`, + body: urls, +}); export const getComment = ({ id }) => fetcher.get(`/id/${id}?url=${url}`); diff --git a/web/app/counter.js b/web/app/counter.js index 5a505008..c3006883 100644 --- a/web/app/counter.js +++ b/web/app/counter.js @@ -9,7 +9,7 @@ if (document.readyState !== 'interactive') { } function init() { - const nodes = document.getElementsByClassName(COUNTER_NODE_CLASSNAME); + const nodes = [].slice.call(document.getElementsByClassName(COUNTER_NODE_CLASSNAME)); if (!nodes) { console.error('Remark42: Can\'t find counter nodes.'); @@ -28,10 +28,14 @@ function init() { return; } - [].slice.call(nodes).forEach(node => { - const url = node.dataset.url || remark_config.url || window.location.href; - api.count({ url, siteId: remark_config.site_id }) - .then(({ count }) => { node.innerHTML = count; }); - }); + const map = nodes.reduce((acc, node) => { + acc[node.dataset.url || remark_config.url || window.location.href] = node; + return acc; + }, {}); + + api.count({ urls: Object.keys(map), siteId: remark_config.site_id }) + .then(res => { + res.forEach(item => (map[item.url].innerHTML = item.count)); + }); }