Don't forget to lycansubscribe

replaced user cache with join to simplify import code

Changed files
+8 -10
app
importers
models
+1 -10
app/importers/base_importer.rb
··· 11 11 def initialize(user_did) 12 12 @did = DID.new(user_did) 13 13 @user = User.find_or_create_by!(did: user_did) 14 - 15 - @uid_cache = { user_did => @user.id } 16 14 @imported_count = 0 17 15 end 18 16 ··· 50 48 post_uri = AT_URI(uri) 51 49 return unless post_uri.is_post? 52 50 53 - post = Post.find_by( 54 - user_id: user_id_for_did(post_uri.repo), 55 - rkey: post_uri.rkey 56 - ) 51 + post = Post.find_by_at_uri(post_uri) 57 52 58 53 if post 59 54 yield({ post: post }) ··· 65 60 @report&.update(queue: { length: @item_queue.length }) 66 61 end 67 62 end 68 - end 69 - 70 - def user_id_for_did(did) 71 - @uid_cache[did] ||= User.find_or_create_by!(did: did) 72 63 end 73 64 end
+7
app/models/post.rb
··· 12 12 13 13 belongs_to :user 14 14 15 + def self.find_by_at_uri(uri) 16 + uri = AT_URI(uri) unless uri.is_a?(AT_URI) 17 + return nil unless uri.is_post? 18 + 19 + Post.joins(:user).find_by(user: { did: uri.repo }, rkey: uri.rkey) 20 + end 21 + 15 22 def at_uri 16 23 "at://#{user.did}/app.bsky.feed.post/#{rkey}" 17 24 end