@@ -50,7 +50,7 @@ def add_branch
5050
5151 error "Branch '#{ branch_name } ' not found. Check 'git branch -a' for available branches." unless repo . branch_exists? ( branch_name )
5252
53- existing = Models ::Branch . find_by ( name : branch_name )
53+ existing = Models ::Branch . first ( name : branch_name )
5454 if existing
5555 info "Branch '#{ branch_name } ' already tracked (#{ existing . commits . count } commits)"
5656 info "Use 'git pkgs update' to refresh"
@@ -59,7 +59,7 @@ def add_branch
5959
6060 Database . optimize_for_bulk_writes
6161
62- branch = Models ::Branch . create! ( name : branch_name )
62+ branch = Models ::Branch . create ( name : branch_name )
6363 analyzer = Analyzer . new ( repo )
6464
6565 info "Analyzing branch: #{ branch_name } "
@@ -100,7 +100,7 @@ def list_branches
100100 puts "Tracked branches:"
101101 branches . each do |branch |
102102 commit_count = branch . commits . count
103- dep_commits = branch . commits . where ( has_dependency_changes : true ) . count
103+ dep_commits = branch . commits_dataset . where ( has_dependency_changes : true ) . count
104104 last_sha = branch . last_analyzed_sha &.slice ( 0 , 7 ) || "none"
105105 puts " #{ branch . name } : #{ commit_count } commits (#{ dep_commits } with deps), last: #{ last_sha } "
106106 end
@@ -115,13 +115,13 @@ def remove_branch
115115
116116 Database . connect ( repo . git_dir )
117117
118- branch = Models ::Branch . find_by ( name : branch_name )
118+ branch = Models ::Branch . first ( name : branch_name )
119119 error "Branch '#{ branch_name } ' not tracked. Run 'git pkgs branch list' to see tracked branches." unless branch
120120
121121 # Only delete branch_commits, keep shared commits
122122 count = branch . branch_commits . count
123- branch . branch_commits . delete_all
124- branch . destroy
123+ branch . branch_commits_dataset . delete
124+ branch . delete
125125
126126 info "Removed branch '#{ branch_name } ' (#{ count } branch-commit links)"
127127 end
@@ -143,28 +143,27 @@ def bulk_process_commits(commits, branch, analyzer, total, repo)
143143 flush = lambda do
144144 return if pending_commits . empty?
145145
146- ActiveRecord :: Base . transaction do
147- # Use upsert for commits since they may already exist from other branches
146+ Database . db . transaction do
147+ # Use insert with on_conflict for commits since they may already exist from other branches
148148 if pending_commits . any?
149- Models ::Commit . upsert_all (
150- pending_commits ,
151- unique_by : :sha
152- )
149+ Models ::Commit . dataset
150+ . insert_conflict ( target : :sha , update : { has_dependency_changes : Sequel [ :excluded ] [ :has_dependency_changes ] } )
151+ . multi_insert ( pending_commits )
153152 end
154153
155154 commit_ids = Models ::Commit
156155 . where ( sha : pending_commits . map { |c | c [ :sha ] } )
157- . pluck ( :sha , :id ) . to_h
156+ . select_hash ( :sha , :id )
158157
159158 if pending_branch_commits . any?
160159 branch_commit_records = pending_branch_commits . map do |bc |
161160 { branch_id : bc [ :branch_id ] , commit_id : commit_ids [ bc [ :sha ] ] , position : bc [ :position ] }
162161 end
163- Models ::BranchCommit . insert_all ( branch_commit_records )
162+ Models ::BranchCommit . dataset . multi_insert ( branch_commit_records )
164163 end
165164
166165 if pending_changes . any?
167- manifest_ids = Models ::Manifest . pluck ( :path , :id ) . to_h
166+ manifest_ids = Models ::Manifest . select_hash ( :path , :id )
168167 change_records = pending_changes . map do |c |
169168 {
170169 commit_id : commit_ids [ c [ :sha ] ] ,
@@ -179,11 +178,11 @@ def bulk_process_commits(commits, branch, analyzer, total, repo)
179178 updated_at : now
180179 }
181180 end
182- Models ::DependencyChange . insert_all ( change_records )
181+ Models ::DependencyChange . dataset . multi_insert ( change_records )
183182 end
184183
185184 if pending_snapshots . any?
186- manifest_ids ||= Models ::Manifest . pluck ( :path , :id ) . to_h
185+ manifest_ids ||= Models ::Manifest . select_hash ( :path , :id )
187186 snapshot_records = pending_snapshots . map do |s |
188187 {
189188 commit_id : commit_ids [ s [ :sha ] ] ,
@@ -196,7 +195,7 @@ def bulk_process_commits(commits, branch, analyzer, total, repo)
196195 updated_at : now
197196 }
198197 end
199- Models ::DependencySnapshot . insert_all ( snapshot_records )
198+ Models ::DependencySnapshot . dataset . multi_insert ( snapshot_records )
200199 end
201200 end
202201
0 commit comments