-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api] improve speed on issue tracking
- Loading branch information
1 parent
298e26d
commit 7b47dc9
Showing
4 changed files
with
78 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,25 @@ | ||
class PackageIssue < ActiveRecord::Base | ||
belongs_to :package | ||
belongs_to :issue | ||
|
||
def self.sync_relations(package, issues) | ||
PackageIssue.transaction do | ||
allissues=[] | ||
issues.map{|h| allissues += h.last} | ||
|
||
# drop not anymore existing relations | ||
PackageIssue.where("package_id = ? AND NOT issue_id IN (?)", package, allissues).delete_all | ||
|
||
# create missing in an efficient way | ||
sql=ActiveRecord::Base.connection() | ||
(allissues - package.issues.to_ary).each do |i| | ||
sql.execute("INSERT INTO `package_issues` (`package_id`, `issue_id`) VALUES (#{package.id},#{i.id})") | ||
end | ||
|
||
# set change value for all | ||
issues.each do |pair| | ||
PackageIssue.where(package: package, issue: pair.last).update_all(change: pair.first) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters