Skip to content

wip: refactor abstract mapreduce#9177

Draft
emilygilberts wants to merge 3 commits intoapache:masterfrom
emilygilberts:refactor-abstract-mapreduce
Draft

wip: refactor abstract mapreduce#9177
emilygilberts wants to merge 3 commits intoapache:masterfrom
emilygilberts:refactor-abstract-mapreduce

Conversation

@emilygilberts
Copy link
Contributor

did some ES6 refactoring:

  • converted functions updatePurgeSeq, saveKeyValues, createTask, getRecentPurges to async/await to replace promise chains

  • refactored postProcessAttatchments to accept the resolved result (res) directly, wich enables to remove the .then()` on the call

  • removed unneccessary promise wrappers around calls of:

  • postProcessAttatchments (is now invoked directly with the resolved result - instead of with .then() chaining)

  • queryPromised (the async function already returns a promise)

  • replaced the use of fin (final promise factory function) with try/finally block

  • removed the last var

note:
currently repeadedly writing out the defaultsto functionality, will take care of it next :)

@emilygilberts emilygilberts marked this pull request as draft February 19, 2026 18:10
throw new Error(row.reason);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this make this code path synchronous instead of asynchronous? I have not looked at the bigger picture yet, but my gut feeling says that handling attachments (large binary values) probably wants to be async?

Copy link
Contributor Author

@emilygilberts emilygilberts Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! I was thinking that its safe on this call since the function addHttpParam is already async and before calling postprocessAttachments we still await the db.fetch and response.json.

I thought that since postprocessAttachments and readAttachmentsAsBlobOrBuffer themselves are synchronous, wrapping the result in a Promise and calling postprocessAttachments on .then() only slightly delays the call? - if not this is definitely where my confusion lies! :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emily and I paired on this and I am now convinced that postprocessAttachments() and further down are all synchronous functions, so that is all fine.

The only thing left here to find out is why the original code does the wrapping in another promise to move the post processing to the next tick.

Maybe @AlbaHerrerias you remember when you made that change [checks notes] a long time ago? ;D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi 👋 unfortunately I do not recall, this was 3 years ago after all. I went to the PR that introduced the change but still no idea, it is true that looks odd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants