Hacker News new | past | comments | ask | show | jobs | submit login
How does ActiveRecord#find work? (omniref.com)
67 points by myShoggoth on Feb 5, 2015 | hide | past | favorite | 28 comments



Hi, author of the post here -- I actually skipped a few steps in this code, because it was getting quite long. As it turns out, ActiveRecord is amazingly complicated, even for the simplest of queries.

It's trying to build an AST for every query, and that AST uses Arel, which is its own, complex layer of abstraction. There are a lot of layers of turtles before you get to anything that looks like SQL.


Awhile ago I found a patch to Arel fixing up its support of unions, which I wanted to use, but it hadn't been merged and had fallen behind the version I was on. Fixing it up for the newer version required enough tweaking that I had to actually figure out how the code worked. I found it to be an impressively simple and well-written solution to an inherently complex problem.

All of this is to say that it would be neat to see this journey go even deeper!


Into Arel, you mean? Happy to do that. It would be a good opportunity to really understand that code better!


Yeah that's what I meant!


Here's an optimization that one of the maintainers of rails is doing (has already done?) on #find

http://tenderlovemaking.com/2014/02/19/adequaterecord-pro-li...


The second step in the omniref story is precisely the optimization Aaron made.

It's the `s = find_by_statement_cache[key] || ..` statement.


that was added as art of rails 4.2.0


My keyboard seems to disregard about 25% of all my p, k, and l key presses. The above should have been part. I'd throw the keyboard out but I love the layout of it. If anyone knows of a Microsoft natural Internet keyboard layout with mechanical switches I'd buy a few immediately. There's got to be a bespoke keyboard business out there somewhere with all the 3d printers nowadays.


I really appreciate what the omniref guys are doing, but I find these "posts" (maybe not the right word?) incredibly difficult to follow. I can't tell if I'm supposed to read the left pane, the right pane, the bubble? Do I click the quote bubbles? Does the left pane "track" the right pane?


A little hard to follow? Only because I've never seen it before. This is a great idea.

The publishing of code-as-narrative or code alongside narrative is something that will slip into the mainstream, maybe in our lifetimes.

Already, ruby code (and other similar languages) are nearly understandable by non-technical folks. And consider the popularity of tools like cucumber that involve tests that are readable by anyone.

Imagine a day when code is published on the New York Times homepage, alongside some Silicon Valley luminary's commentary.


Maybe we can get Morgan Freeman to narrate the source code of TeX.


In this case, the "bubble" is the thing...but yeah, it's a little noisy. Perhaps if we fuzzed out the background a bit when the annotation viewer (the bubble) is open it would help?


Please don't do this. It was immediately obvious to me which part was the part I was supposed to read. (And I've never visited this site before today!)


Hah...we'll put it in the "maybe" folder for now.


[flagged]


Look, man. Until one gets a sample size that's a fair bit larger than two, one cannot know whether the person professing confusion or the person professing clarity represents the more common case.

Chill.


I personally managed to follow the series without difficulty, though I can sympathize with the parent's sentiment because I felt a brief moment of confusion when the page first loaded. Excellent write up though! Looking forward to going through the rest of the content after work today.


I'm no UX expert, but I think if you want story reading to be a core feature of your product it will have to have a core place in your layout, so not a pop up box. It would replace whatever currently is your main feature (I.e it would become the left bar).


I think the thing to do might be to detect if the page was loaded with the annotation open, then fuzz background. Otherwise, you know what you're looking at and explicitly clicked the open annotation button.

It's great that the site supports such deep linking.


I'm interested in a productive dialog; I'm not trying to engage in an attack here.

Doesn't your suggestion harm the UX for the person who has spent the minute or two required to figure out how to operate the site?

Even from my very first visit earlier today, I found great value in being able to read the annotated code and the annotation simultaneously.


My original comment was worded poorly. Left side blur should be on initial load if the referring url is not from the same site, not every time you open an annotation.


I think they're talking about fuzzing the left pane background, not the code pane.


Yep, that's the proposal I'm making.


That was a neat investigation and use of omniref.

I just posted a question: https://www.omniref.com/ruby/gems/activerecord/4.2.0/symbols...

I see that it popped up under recent questions on the home page. Once a question gets bumped off that list, is there an easy way to find it (e.g. through search) or can one only find it if they happen to be viewing the Q&A tab under the same file?

Since this is my first question there, I'm not sure if I have to check back repeatedly for answers or if I'll get notified somehow.


I love these, great work. One minor nitpick; the next/previous links seem like they're backwards: I ended up hitting previous by mistake twice, thinking I was moving forwards.


Because the links are actually wrong, or because they're in a confusing order? If they're wrong somewhere, definitely let me know!


Is there an Omniref equivalent for Java?


There will be...as soon as we build it. ;-)

(seriously, though: vote registered for Java as our next language.)


I'll second that vote. Very cool stuff guys.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: