refactor(server): inline file hashing via Transform stream#27280
refactor(server): inline file hashing via Transform stream#27280MartB wants to merge 2 commits intoimmich-app:mainfrom
Conversation
|
This PR has been automatically closed as the description doesn't follow our template. After you edit it to match the template, the PR will automatically be reopened. |
|
@danieldietzler Thats what i get for not sticking to the template even for simple edits i guess! Is the reopen broken or did i miss something? |
There was a problem hiding this comment.
Could you elaborate on what the anti-pattern here is and what this PR actually improves? I just see a Transform abstraction added here that doesn't seem to do anything beneficial compared to the original. I had to look up what it does, which isn't really a point in favor of the change.
Edit: looking at it more closely, there's no backpressure benefit here either. The hashing is synchronous in a single-threaded language; backpressure doesn't apply. The Transform is just indirection.
|
@mertalev However the real reason this was spotted initially, is because it mixes automatic (pipeline) with manual (.on(“data”)) code. So we are left with "just" a code quality / hardening improvement. |
|
Yeah I thought about this too. Using a transform stream might be clearer maybe in the order of operations of the pipeline, but this isn't a bug fix and it doesn't make the behaviour any better or worse. It's just stylistic, which is why I didn't do it. |
uhthomas
left a comment
There was a problem hiding this comment.
If we are going to do this, let's flesh it out more. The transform stream should destroy the hash, not the pipeline.
|
Let's also maybe rename it? It's not just hashing, it's also tracking the size of the file. |
|
The other trouble with using transforms is that there is an opportunity to break it. The event listener version is purely read-only, and the code makes that intention clear. |
|
Yeah, it's kind of like calling array.map, doing a side effect and returning the input. |
Description
This change refactors the original implementation to avoid an anti-pattern
and improve back pressure handlingThis assumption was wrong see comments below.Fixes nothing so far
How Has This Been Tested?
Screenshots (if appropriate)
Checklist:
src/services/uses repositories implementations for database calls, filesystem operations, etc.src/repositories/is pretty basic/simple and does not have any immich specific logic (that belongs insrc/services/)Please describe to which degree, if any, an LLM was used in creating this pull request.
None