Last active
December 20, 2022 16:29
-
-
Save rishabg/d6e23ac1ad278cd71f765706e5bab3e0 to your computer and use it in GitHub Desktop.
Revisions
-
rishabg revised this gist
Dec 20, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,14 +6,14 @@ # Hint: There are multiple issues here. First try to list all of them before attempting possible solutions # Hint: Assume that the file is already present locally (ignore the network transfer process for the file) # As a final step: Discuss how you would go about investigating and improving: slow_method_that_updates_multiple_models csv_file = CSV.parse(File.read(yuuge_csv_file), col_sep: self.separator, headers: true) ComplexModel.transaction do csv_file.each do |row| obj = ComplexModel.find(row[0]) obj.children.each do |child| child.slow_method_that_updates_multiple_models(row) end end end -
rishabg created this gist
Jan 20, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ # Discuss how you would speed this up Given that: # 1. CSV file can be very large # 2. Processing happens as within a webrequest (server timeout = 2 min) # 3. Not all optimizations are code-related. You are free to ask about possible functionality changes or side-effects. # Hint: There are multiple issues here. First try to list all of them before attempting possible solutions # Hint: Assume that the file is already present locally (ignore the network transfer process for the file) # As a final step: Discuss how you would go about investigating and improving: slow_process_that_updates_multiple_models csv_file = CSV.parse(File.read(yuuge_csv_file), col_sep: self.separator, headers: true) ComplexModel.transaction do csv_file.each do |row| obj = ComplexModel.find(row[0]) obj.children.each do |child| child.slow_process_that_updates_multiple_models(row) end end end