tiddlyhost / tiddlyhost-com

Rails application for creating and hosting TiddlyWiki sites, plus resources for deploying it to https://tiddlyhost.com/
Other
188 stars 18 forks source link

Attachment dupes are a problem #245

Closed simonbaird closed 2 years ago

simonbaird commented 2 years ago

Sometime the "purge_later" job fails. I don't know the reason for it, but the result is a stale leftover blob. This wouldn't be a problem, except that (it appears?) the stale blob is the one that is returned by the tiddlywiki_file assocation. This is a big problem because if the user reloads their site they get the old version, effectively losing the latest save.

Solution ideas:

simonbaird commented 2 years ago

I tried to reproduce the symptom locally by disabling the purge later job, and I wasn't able to. So I think there's something else going on. What happens is (somehow) the old ActiveStorage::Attachment record is still associated with the site, even though it should be not possible for a has_one_attachment association.

This makes me think maybe there's an error message produced when it happens.

simonbaird commented 2 years ago

For the order by workaround, I think this might do it:

+ActiveStorage::Attachment.class_eval do
+  default_scope { order('created_at DESC') }
+end

But I haven't been able to confirm it yet.

(It's not the blob that needs it, as I suggested originally, it's the attachment.)

simonbaird commented 2 years ago

A dupe appeared, and afaict the workaround is effective. I'll close this tentatively.