Skip to content

Commit

Permalink
fix: 🐛 enable memoize
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Sep 4, 2022
1 parent 3283e18 commit b571fca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 45 deletions.
20 changes: 11 additions & 9 deletions packages/analytics/src/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ export default function combine(data, feed) {
append: this.getParam('append'),
});
this.databaseID = hashCoerce.hash({ primer, commands });
const statements = ezs.compileCommands(commands, this.getEnv());
const output = ezs.createPipeline(input, statements)
.pipe(ezs(saveIn, null, this.databaseID))
.pipe(ezs.catch())
.on('data', (d) => assert(d)) // WARNING: The data must be consumed, otherwise the "end" event has not been triggered
.on('error', (e) => feed.stop(e));
whenReady = new Promise((resolve) => output.on('end', resolve));
input.write(primer);
input.end();
if (!database[this.databaseID]) {
const statements = ezs.compileCommands(commands, this.getEnv());
const output = ezs.createPipeline(input, statements)
.pipe(ezs(saveIn, null, this.databaseID))
.pipe(ezs.catch())
.on('data', (d) => assert(d)) // WARNING: The data must be consumed, otherwise the "end" event has not been triggered
.on('error', (e) => feed.stop(e));
whenReady = new Promise((resolve) => output.on('end', resolve));
input.write(primer);
input.end();
}
}
if (this.isLast()) {
return feed.close();
Expand Down
57 changes: 21 additions & 36 deletions packages/analytics/test/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,25 @@ const env = {
executed: false,
};
const cacheName = Date.now();
const cacheScript = `
[use]
plugin = analytics
test.skip('combine with cache with script #1', (done) => {
[env]
path = executed
value = fix(true)
[replace]
path = value
value = fix({id:'a', value:'aa'},{id:'b', value:'bb'},{id:'c', value:'cc'},{id:'d', value:'dd'},{id:'e', value:'ee'},{id:'f', value:'ff'})
[exploding]
[value]
`;



test('combine with internal cache with script #1', (done) => {
ezs.use(statements);
const input = [
{ a: 1, b: 'a' },
Expand All @@ -396,24 +413,8 @@ test.skip('combine with cache with script #1', (done) => {
{ a: 6, b: 'f' },
];
const output = [];
const script = `
[use]
plugin = analytics
[env]
path = executed
value = fix(true)
[replace]
path = value
value = fix({id:'a', value:'aa'},{id:'b', value:'bb'},{id:'c', value:'cc'},{id:'d', value:'dd'},{id:'e', value:'ee'},{id:'f', value:'ff'})
[exploding]
[value]
`;

from(input)
.pipe(ezs('combine', { path: 'b', script, cacheName }, env))
.pipe(ezs('combine', { path: 'b', script: cacheScript }, env))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
Expand All @@ -433,7 +434,7 @@ test.skip('combine with cache with script #1', (done) => {
});
});

test.skip('combine with cache with script #2', (done) => {
test('combine with internal cache with script #2', (done) => {
ezs.use(statements);
const input = [
{ a: 1, b: 'a' },
Expand All @@ -444,24 +445,8 @@ test.skip('combine with cache with script #2', (done) => {
{ a: 6, b: 'f' },
];
const output = [];
const script = `
[use]
plugin = analytics
[env]
path = executed
value = fix(true)
[replace]
path = value
value = fix({id:'a', value:'aa'},{id:'b', value:'bb'},{id:'c', value:'cc'},{id:'d', value:'dd'},{id:'e', value:'ee'},{id:'f', value:'ff'})
[exploding]
[value]
`;

from(input)
.pipe(ezs('combine', { path: 'b', script, cacheName }, env))
.pipe(ezs('combine', { path: 'b', script: cacheScript }, env))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
Expand Down

0 comments on commit b571fca

Please sign in to comment.