Skip to content

Commit d4897e2

Browse files
committed
reenable stats extensions for Preview/Chatbot staging
with optimization (memory) for the component stats wordcount
1 parent 6e67f3c commit d4897e2

5 files changed

Lines changed: 30 additions & 8 deletions

antora-playbook-staging-chatbot.diff.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
antora:
22
extensions:
33
- ./lib/report-tree.js
4-
# - ./lib/site-stats-extension.js
4+
- ./lib/site-stats-extension.js
5+
- ./lib/component-stats.js
56

67
site:
78
title: Couchbase Docs Staging Chatbot

antora-playbook-staging-chatbot.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ antora:
2626
- ./lib/embargo.js
2727
- ./lib/antora-component-version-rank.js
2828
- ./lib/report-tree.js
29+
- ./lib/site-stats-extension.js
30+
- ./lib/component-stats.js
2931
site:
3032
title: Couchbase Docs Staging Chatbot
3133
url: https://chatbot-staging.docs-test.couchbase.com
@@ -139,16 +141,16 @@ content:
139141
- main
140142
- url: https://github.com/couchbase/couchbase-operator
141143
branches:
144+
- 2.9.x
142145
- 2.8.x
143146
- 2.7.x
144-
- 2.6.x
145147
start_path: docs/user
146148
- url: https://github.com/couchbase/docs-operator
147149
branches:
148150
- release/2.8.1
151+
- release/2.9
149152
- release/2.8
150153
- release/2.7
151-
- release/2.6
152154
- url: https://github.com/couchbaselabs/observability
153155
branches:
154156
- 0.2.x

antora-playbook.preview.diff.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ antora:
55
extensions:
66
- ./lib/preview.js
77
- ./lib/report-tree.js
8-
# - ./lib/site-stats-extension.js
9-
# - ./lib/component-stats.js
8+
- ./lib/site-stats-extension.js
9+
- ./lib/component-stats.js
1010

1111
site:
1212
title: Couchbase Docs Preview

antora-playbook.preview.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ antora:
2424
- ./lib/antora-component-version-rank.js
2525
- ./lib/preview.js
2626
- ./lib/report-tree.js
27+
- ./lib/site-stats-extension.js
28+
- ./lib/component-stats.js
2729
site:
2830
url: https://docs.couchbase.com
2931
start_page: home::index.adoc
@@ -101,19 +103,19 @@ content:
101103
- main
102104
- url: https://github.com/couchbase/couchbase-operator
103105
branches:
106+
- 2.9.x
104107
- 2.8.x
105108
- 2.7.x
106109
- 2.6.x
107110
- 2.5.x
108-
- 2.4.x
109111
start_path: docs/user
110112
- url: https://github.com/couchbase/docs-operator
111113
branches:
114+
- release/2.9
112115
- release/2.8
113116
- release/2.7
114117
- release/2.6
115118
- release/2.5
116-
- release/2.4
117119
- url: https://github.com/couchbaselabs/observability
118120
branches:
119121
- 0.2.x

lib/component-stats.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const {JSDOM} = require('jsdom')
22

33
module.exports.register = function () {
44
this.once('sitePublished', ({ playbook, contentCatalog }) => {
5+
6+
console.time('get-component-stats')
7+
58
contentCatalog.getComponents().forEach((component) => {
69
component.versions.forEach((componentVersion, index) => {
710
const pages = contentCatalog.getPages(it => it.src.component === componentVersion.name && it.src.version === componentVersion.version)
@@ -22,14 +25,28 @@ module.exports.register = function () {
2225
})
2326
})
2427
})
28+
29+
console.timeEnd('get-component-stats')
2530
})
2631
}
2732

2833
function wordcount (words) {
2934
// very dumb wordcount function
3035
// won't deal gracefully with non-western scripts (which is fine for our use-case
3136
// as we don't have material content in those languages)
32-
return words.split(/\s+/).length
37+
38+
// we are doing essentially the moral equivalent of:
39+
// // return words.split(/\s+/).length
40+
// but we iterate the regexp, to avoid building up a huge data-structure
41+
// e.g. we trade off some speed in order to bound memory usage.
42+
43+
const re = /\s+/g
44+
45+
let count = 0
46+
while (re.exec(words)) {
47+
++count;
48+
}
49+
return count
3350
}
3451

3552
function sum (nums) {

0 commit comments

Comments
 (0)