Hacker Newsnew | past | comments | ask | show | jobs | submit | simonw's favoriteslogin

You could probably get this down to two queries, one for posts and one for comments, if you aggregate the vote count when retrieving the comments. I think this is pretty easy to do with most ORMs.

You could also get it down to 1 query using SQL. This is one way to do it based on the schema in the article [postgres, not well tested]:

    with
      latest_posts as (
        select * from post limit 3
      ),
      latest_comments as (
        select
          c.*, count(v.id) as votes
        from
          comment c
        left join
          vote v on v.comment_id = c.id
        where
          c.post_id in (select id from latest_posts)
        group by
          c.id, c.content
      )
    select
      p.*, json_agg(c)
    from
      latest_posts p
    left join
      latest_comments c on c.post_id = p.id
    group by
      p.id, p.title, p.content

    # NOTE: fixed SQL bug noted by @rurabe
Off the top of my head, I'm not sure how you would (or if you could) do this with ActiveRecord, SQLAlchemy, or the Django ORM, but it's probably more complicated than just writing the SQL.

To be clear, I'm not anti-ORM and use them all the time, but it really helps to understand SQL well when using them and to know when it's appropriate to switch to SQL.


In my opinion, microservices are all the rage because they're an easily digestible way for doing rewrites. Everyone hates their legacy monolith written in Java, .NET, Ruby, Python, or PHP, and wants to rewrite it in whatever flavor of the month it is. They get buy in by saying it'll be an incremental rewrite using microservices.

Fast forward to six months or a year later, the monolith is still around, features are piling up, 20 microservices have been released, and no one has a flipping clue what does what, what to work on or who to blame. The person who originally sold the microservice concept has left the company for greener pastures ("I architected and deployed microservices at my last job!"), and everyone else is floating their resumes under the crushing weight of staying the course.

Proceed with caution.


They implement a trained dense multilayer neural net wit ReLU activations in silicon photonics. They evaluate it on MNIST.

They use graphene to approximate the ReLUs. The device is a few microns on each side.

The 2D image is first converted to a 1D wavefront by some external means, then launched into the side of the device.

Training happens in digital computer, by simulating the behavior of the device.

Full paper: https://arxiv.org/pdf/1810.07815.pdf


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: