From 18e4dad6fcad6e518ef77b3ed91f3a834b5d7479 Mon Sep 17 00:00:00 2001 From: Andrei Lisnic Date: Fri, 20 Sep 2024 12:14:12 +0300 Subject: [PATCH 1/9] perf: Reduce GC pressure by avoiding EJSON.clone --- lib/cache/ObservableCollection.js | 5 +++-- lib/mongo/ObserveMultiplex.js | 19 ++++++++++++++----- package.js | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/cache/ObservableCollection.js b/lib/cache/ObservableCollection.js index 127171df..5545b282 100644 --- a/lib/cache/ObservableCollection.js +++ b/lib/cache/ObservableCollection.js @@ -196,11 +196,12 @@ export default class ObservableCollection { * @param safe {Boolean} If this is set to true, it assumes that the object is cleaned */ add(doc, safe = false) { - doc = EJSON.clone(doc); - if (!safe) { if (this.fieldsArray) { + // projection function clones the document already. doc = this.projectFieldsOnDoc(doc); + } else { + doc = EJSON.clone(doc); } } diff --git a/lib/mongo/ObserveMultiplex.js b/lib/mongo/ObserveMultiplex.js index 53e0c103..3a80c64c 100644 --- a/lib/mongo/ObserveMultiplex.js +++ b/lib/mongo/ObserveMultiplex.js @@ -41,6 +41,15 @@ export function ObserveMultiplexer(options) { }); } +function strictFreeze(obj) { + return new Proxy(obj, { + set() { + throw new Error('Cannot mutate a frozen object'); + } + }); +} +const freezeObject = Meteor.isProduction ? Object.freeze : strictFreeze + Object.assign(ObserveMultiplexer.prototype, { addHandleAndSendInitialAdds: function(handle) { var self = this; @@ -213,16 +222,17 @@ Object.assign(ObserveMultiplexer.prototype, { // can continue until these are done. (But we do have to be careful to not // use a handle that got removed, because removeHandle does not use the // queue; thus, we iterate over an array of keys that we control.) + const safeArgs = freezeObject(args); + Object.keys(self._handles).forEach(function(handleId) { var handle = self._handles && self._handles[handleId]; if (!handle) return; var callback = handle['_' + callbackName]; - // clone arguments so that callbacks can mutate their arguments // We silence out removed exceptions if (callback === 'removed') { try { - callback.apply(null, EJSON.clone(args)); + callback.apply(null, safeArgs); } catch (e) { // Supressing `removed non-existent exceptions` if (!isRemovedNonExistent(e)) { @@ -230,7 +240,7 @@ Object.assign(ObserveMultiplexer.prototype, { } } } else { - callback && callback.apply(null, EJSON.clone(args)); + callback && callback.apply(null, safeArgs); } }); }); @@ -250,8 +260,7 @@ Object.assign(ObserveMultiplexer.prototype, { self._cache.docs.forEach(function(doc, id) { if (!_.has(self._handles, handle._id)) throw Error('handle got removed before sending initial adds!'); - var fields = EJSON.clone(doc); - delete fields._id; + const { _id, ...fields } = doc if (self._ordered) add(id, fields, null); // we're going in order, so add at end else add(id, fields); diff --git a/package.js b/package.js index 48bebfa5..3e0d4a19 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'cultofcoders:redis-oplog', - version: '2.2.2', + version: '2.3.0', // Brief, one-line summary of the package. summary: "Replacement for Meteor's MongoDB oplog implementation", // URL to the Git repository containing the source code for this package. From 2c5f01627f720f4b6b7ce5ea0fd5e3cb320df1ac Mon Sep 17 00:00:00 2001 From: Andrei Lisnic Date: Fri, 27 Sep 2024 10:14:47 +0300 Subject: [PATCH 2/9] Remove Meteor 1.x from Meteor matrix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 321a5cba..63fe4ecf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - meteor: [1.12.2, 2.8.1, 2.12, 2.15] + meteor: [2.8.1, 2.12, 2.15] redis-version: [4, 5, 6, 7] steps: From 790c41ec7c08bf6cdc0a8b7345a384721e635ae4 Mon Sep 17 00:00:00 2001 From: Andrei Lisnic Date: Mon, 14 Oct 2024 17:28:28 +0300 Subject: [PATCH 3/9] Try bump setup-meteor action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 63fe4ecf..480c5dd8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: redis-version: ${{ matrix.redis-version }} - name: Setup Meteor - uses: meteorengineer/setup-meteor@v1 + uses: meteorengineer/setup-meteor@v2 with: meteor-release: ${{ matrix.meteor }} - name: Setup tests From 26d5ded98095640463dcdb23d3eea9cbf0ecd2bf Mon Sep 17 00:00:00 2001 From: Andrei Lisnic Date: Mon, 14 Oct 2024 17:31:39 +0300 Subject: [PATCH 4/9] Revert "Try bump setup-meteor action" This reverts commit 790c41ec7c08bf6cdc0a8b7345a384721e635ae4. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 480c5dd8..63fe4ecf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: redis-version: ${{ matrix.redis-version }} - name: Setup Meteor - uses: meteorengineer/setup-meteor@v2 + uses: meteorengineer/setup-meteor@v1 with: meteor-release: ${{ matrix.meteor }} - name: Setup tests From ffe6d57d84c547c65b01a421282641dfffff4a53 Mon Sep 17 00:00:00 2001 From: Andrei Lisnic Date: Mon, 14 Oct 2024 17:54:09 +0300 Subject: [PATCH 5/9] Pin chai version --- .github/workflows/test.yml | 2 +- .gitignore | 1 + CONTRIBUTING.md | 13 +++++++------ package.js | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 63fe4ecf..7b583557 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: run: | meteor create --release ${{ matrix.meteor }} --bare test cd test - meteor npm i --save puppeteer@1.18.1 simpl-schema@1.13.1 chai + meteor npm i --save puppeteer@1.18.1 simpl-schema@1.13.1 chai@4 - name: Test working-directory: ./test run: METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ diff --git a/.gitignore b/.gitignore index 04913f99..3668c4f1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ npm-debug.log .idea/ test/ +node_modules/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d5584094..4f320225 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,8 @@ First, thank you for considering contributing to redis-oplog! It's people like you that make the open source community such a great community! 😊 -We welcome any type of contribution, not only code. You can help with +We welcome any type of contribution, not only code. You can help with + - **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open) - **Marketing**: writing blog posts, howto's, printing stickers, ... - **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ... @@ -13,7 +14,7 @@ We welcome any type of contribution, not only code. You can help with ## Your First Contribution -Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). +Working on your first Pull Request? You can learn how from this _free_ series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). ## Submitting code @@ -26,14 +27,16 @@ It is also always helpful to have some context for your pull request. What was t ## Running Tests -### Setup +### Setup + ``` meteor create --release 1.12.2 --bare test cd test -meteor npm i --save puppeteer@1.18.1 simpl-schema chai +meteor npm i --save puppeteer@1.18.1 simpl-schema chai@4 ``` ### Start Tests + ``` METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../ ``` @@ -55,14 +58,12 @@ You can also reach us at hello@redis-oplog.opencollective.com. Thank you to all the people who have already contributed to redis-oplog! - ### Backers Thank you to all our backers! [[Become a backer](https://opencollective.com/redis-oplog#backer)] - ### Sponsors Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/redis-oplog#sponsor)) diff --git a/package.js b/package.js index 3e0d4a19..77e9d8d0 100644 --- a/package.js +++ b/package.js @@ -17,7 +17,7 @@ Npm.depends({ }); Package.onUse(function(api) { - api.versionsFrom(['1.12.2', '2.8.1', '2.13', '2.15']); + api.versionsFrom(['2.8.1', '2.13', '2.15']); api.use([ 'underscore', 'ecmascript', From b2100f4b27ad7694858353cc76cf6c89aa66cc66 Mon Sep 17 00:00:00 2001 From: Andrei Lisnic Date: Mon, 14 Oct 2024 17:58:19 +0300 Subject: [PATCH 6/9] Try another ubuntu --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7b583557..ad72a0bc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: matrix: meteor: [2.8.1, 2.12, 2.15] From f0c6dbed7413bbfa6e9918fa2e4492a50ceb032e Mon Sep 17 00:00:00 2001 From: Andrei Lisnic Date: Mon, 14 Oct 2024 18:00:45 +0300 Subject: [PATCH 7/9] Revert "Remove Meteor 1.x from Meteor matrix" This reverts commit 2c5f01627f720f4b6b7ce5ea0fd5e3cb320df1ac. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ad72a0bc..643238df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - meteor: [2.8.1, 2.12, 2.15] + meteor: [1.12.2, 2.8.1, 2.12, 2.15] redis-version: [4, 5, 6, 7] steps: From ffc792c96c08caa4dc73974e7fdb3e63410e9af6 Mon Sep 17 00:00:00 2001 From: Andrei Lisnic Date: Mon, 14 Oct 2024 18:01:23 +0300 Subject: [PATCH 8/9] Add back 1.x version --- package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.js b/package.js index 77e9d8d0..3e0d4a19 100644 --- a/package.js +++ b/package.js @@ -17,7 +17,7 @@ Npm.depends({ }); Package.onUse(function(api) { - api.versionsFrom(['2.8.1', '2.13', '2.15']); + api.versionsFrom(['1.12.2', '2.8.1', '2.13', '2.15']); api.use([ 'underscore', 'ecmascript', From 14955af513e11cd11f81f0112978d2c0b8fddee3 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Tue, 26 Nov 2024 12:28:44 +0900 Subject: [PATCH 9/9] Try to trigger workflow --- .github/workflows/test.yml | 2 +- package.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 643238df..1ab5a8da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: redis-version: ${{ matrix.redis-version }} - name: Setup Meteor - uses: meteorengineer/setup-meteor@v1 + uses: meteorengineer/setup-meteor@v2 with: meteor-release: ${{ matrix.meteor }} - name: Setup tests diff --git a/package.js b/package.js index 3e0d4a19..a5ac9cc0 100644 --- a/package.js +++ b/package.js @@ -17,7 +17,7 @@ Npm.depends({ }); Package.onUse(function(api) { - api.versionsFrom(['1.12.2', '2.8.1', '2.13', '2.15']); + api.versionsFrom(['1.12.2', '2.8.1', '2.13', '2.15', '2.16']); api.use([ 'underscore', 'ecmascript',