isovector / take2

the real accio analytics platform
7 stars 2 forks source link

Lots of create() methods in models add a row, then find it again and return it #67

Closed edmundnoble closed 9 years ago

edmundnoble commented 9 years ago

The title. I don't understand this pattern; it looks like a waste of I/O. I'm no Slick expert, though. The problem is a lot of create() methods unnecessarily access the database when the data they're looking for is already there.

isovector commented 9 years ago

yeah, it's definitely gnarly. we ran into a problem where to-and-from foreign references would overflow the stack when slick created them. the "pattern" is that any instance of the model should come from the flyweight so that all instances in memory refer to the same object. I didn't write support for creation into the flyweight, so this is our hack to get the right behavior.

lensing the id to the newly returned row id, and putting that in the flyweight would be an okay solution; fixing the flyweight would be better =)

edmundnoble commented 9 years ago

I think I've fixed the flyweight in this respect. I'll open a pull request soon. Let me know if it's broken.