Last active
December 20, 2022 16:29
-
-
Save rishabg/d6e23ac1ad278cd71f765706e5bab3e0 to your computer and use it in GitHub Desktop.
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 characters
| # 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_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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment