DEV Community

Cover image for Wednesday Week 3: Deliveries
Will Martin
Will Martin

Posted on • Edited on

Wednesday Week 3: Deliveries

We made a food delivery app with separate models for employees, customers, meals and orders, with a session controller to manage employee vs manager sign-ins and permissions. This is the most complex thing I’ve made. I’m still getting used to separate file dependencies and requiring the right class in the right place.
I really wish I had two monitors here. I’d always thought that people with a multiple-screen setup were flexing. The amount of shifting between tabs when working with multiple models though, plus looking at lecture slides and googling issues. If someone had walked in and hooked me up with two more screens I’d have started crying and given them a hug. I need to finally invest in a desktop soon. I’ve wanted to build my own pc for a long time, something to think about when I get back to Chengdu.

def load_csv
    csv_options = { headers: :first_row, header_converters: :symbol }
    CSV.foreach(@csv_file, csv_options) do |row|
      row[:id] = row[:id].to_i
      @customers << Customer.new(row)
    end
    @next_id = @customers.last.id + 1 unless @customers.empty?
  end
Enter fullscreen mode Exit fullscreen mode

The code above iterates over each entry in a database of customers and pushes them to an array as an instantiation of the Customer class, pushing them to an array in the repository.
There’s a lot of writing here. I can see that a database with thousands or tens-of-thousands of entries is going to run very slowly with this loop. Can anyone tell me at what point (size of table) one would move from a csv to a database using SQL? Is there a best practice size limit for practical use of csv’s? If anyone has some neat refactoring for this code I’d love to see it.

My uncle made a website for his business in the '90s. I remember my dad showing me the site as a kid and telling me that it had been built with words. It sounded like magic to me at the time (and definitely something I'd never be capable of). I asked my uncle about it this week and he sent me the original source code. He'd written it out in Word which boggles my mind. I'm looking forward to looking at it this weekend.

Top comments (0)