-
Notifications
You must be signed in to change notification settings - Fork 4
[_] feat: allow empty files on creation and replacement #826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
7545445 to
8ec988b
Compare
| const lockFileId = | ||
| newFileData.fileId || oldFileData.fileId || newFileData.uuid; | ||
| const lockKey = `file-size-change:${lockFileId}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defensive lock key selection to prevent race conditions during file replacement:
Scenario 1: oldFileId exists, newFileId is null (replacing file with empty file)
- lockKey = oldFileId
- delta = oldSize - 0
- Usage replacement IS created
Scenario 2: oldFileId is null, newFileId is null (replacing empty file with empty file)
- lockKey = uuid (fallback)
- delta = 0 - 0
- NO usage replacement created (safe - no actual usage change)
Scenario 3: oldFileId is null, newFileId exists (replacing empty file with actual file)
- lockKey = newFileId
- delta = 0 - newSize
- Usage replacement IS created
I know it is somehow inconsistent but this is the only way we have (for the time being) to protect us from duplicated usage records when allowing empty files without modifying too much things, let's see if there's a better way when I take the ticket I created today @sg-gs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scenario 2 is just a fallback as inside the service we always check if delta != 0. We never create a replacement usage record with delta = 0.
8ec988b to
42027f1
Compare
src/modules/file/file.usecase.ts
Outdated
| ]); | ||
|
|
||
| if ( | ||
| !limit || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For free users, it would be a good idea to throw a 402 for the frontend (upgrade to get more features)
|
Hey @apsantiso! Shouldn't the fileId from file.dto be modified as
|
True, modified @larryrider |
f579670 to
994981c
Compare
994981c to
15621b6
Compare
15621b6 to
b57b8f8
Compare
|



Adds support for empty files (size = 0) during file creation and replacement. Empty files now have
nullfileId values instead of requiring a network file identifier, reducing unnecessary network storage usage.Changes
CreateFileDtoandReplaceFileDtoto makefileIdoptional and conditionally required only when size > 0MaxZeroSizeFilesfeature limitfileId = nullwhensize = 0newFileIdwhen replacing empty file with actual fileoldFileIdwhen replacing actual file with empty fileuuidonly when both files are empty. No usage change and no record in usages table is created as we always check if delta = 0 before creating a record in the usages table.Depends on:
#824