isomerpages / isomercms-backend

A static website builder and host for the Singapore Government
5 stars 1 forks source link

fix: add conditional sha calc #1072

Closed harishv7 closed 10 months ago

harishv7 commented 10 months ago

fix for renaming subfolders

context

We made a change to fast load images as huge repos with a lot of images had very slow load times.

We used to do: get all files -> calculate hash -> filter/paginate Now, we get all files -> filter/paginate -> calculate hash

For the get all files to be fast, we removed the sha calculation in the first step of get all files. However, this affected other ops which use list directory contents

Specifically, when we try to rename a subfolder, we need to delete the current directory and re-create a new one When deleting the current directory, it uses list directory method, but the sha is not present. So when it does a verification of oldSha === newSha, it fails as oldSha is undefined. This causes BE to think that the file was recently changed, so it blocks the delete operation.

Hence, the rename op fails, and we do a rollback. We return 409 saying someone edited the file.

tests

seaerchin commented 10 months ago

@harishv7 got 1 failing test btw maybe need fix