List all uploads of a Post/Topic

AI-generated summary

A discussion on listing all uploads of a post/topic is underway. leo.proctor inquired about a method to list all post uploads, noting that the Post model has defined relations (has_many :post_uploads and has_many :uploads, through: :post_uploads) but are not being utilized. tgxworld clarified that post.uploads can be used to fetch all uploads belonging to a post, and that PostUpload is used in the through: :post_uploads relation.

leo.proctor tested the method and found that it didn’t work as expected, but tgxworld pointed out that the relationship is created asynchronously by Sidekiq. leo.proctor discovered that the issue was due to a plugin for private attachments not storing absolute URLs in a/@href, which is used by keep_reverse_index_up_to_date to determine uploads.

Is there any method defined that lists all the uploads of a post or tell us which post upload belongs to? I see there are relations defined in Post model

has_many :post_uploads
has_many :uploads, through: :post_uploads

But it is hardly used. If I upload an image to a post, it updates the “raw” field in Post to determine the uploads. There is no direct relationship. Why PostUpload is not used?

@tgxworld might know.

@leo.proctor

With any instance of Post, you can do post.uploads to fetch all the Uploads that belong to a post.

PostUpload is being used in through: :post_uploads. I think there might be some confusion here. Perhaps you can provide me with more context?

@tgxworld

I pulled the latest code from master, created a new topic and uploaded an image. Now in rails console

Post.last.uploads # =>
PostUpload.count # => 0
Upload.last #=> contains the uploaded image
Post.last.raw #=> contains a link to uploaded image

Is Sidekiq running? The relationship is only created in

Ah thanks, I think I found the problem. keep_reverse_index_up_to_date uses a/@href value to determine upload. I’m currently using a plugin for private attachments, that doesn’t store absolute url of attachments in a/@href. I may need to overwrite keep_reverse_index_up_to_date. Thanks anyways :slight_smile: