(What a title…) I was pulling my hair out over the last two days when I was implementing bulk operations in a project of mine.
In this case, the list of operations to do in bulk is compiled in the browser, and then the single requests are sent one by one to the server as single AJAX requests. (Think “mark this as read” functionality.)
My problem was that the first and second call in the bulk list usually went through well, but the rest of the calls just ran against a wall since all of a sudden Rails had problems finding the either logged in user or was missing certain methods and/or attributes. Highly annoying as well as completely erratic, as I was sure my code was okay in the first place.
When trying the same operations on a one-by-one basis, all was good. No issues whatsoever.
So while trying to figure out what the fuck was going on, I’ve played around with different ways to get the current user, checking for the availability of its methods and so on, all to no avail.
At one point I’ve disabled the protect_from_forgery call, and one or two different errors started to appear:
A copy of ApplicationController has been removed from the module tree but is still active
That was new. So I’ve started digging around for an answer, and found it in an old Ruby Forum thread.
Turns out that Rails’ development mode was the culprit, as the app’s code is reloaded on every request; so when a lot of concurrent calls are made, the code might reload slower than the calls are coming in and hijinks ensues.
The overly simple solution to this problem? In /config/environments/development.rb, I just set config.cache_classes to true, meaning the code isn’t reloaded all the time — and as it turns out, my code runs just fine after all! Happy happy joy joy.
The downside is that I’ll have to restart my dev server every time I make a code change, but in this particular case, that’s not a big deal.
Yesterday’s Munich on Rails meetup was the usual mix of interesting talks and geeky, delightful conversations. When I say “usual”, I of course mean it’s been the kind of evening I by now kind of expect. ;) Many thanks to Roland for organizing and the Experteers guys for the venue and the food. Nom!
Anyways: interesting talks.
Marco Otte-Witte presented his Excellent gem (gotta love the name) for static code analysis. It’s mostly aimed towards checking Rails code for smell, although —and he made that clear— it’s not targetted at people who strive for the blissful state of “zero warnings”. It’s more relaxed in that way; merely showing you unusual (or stupid or silly) parts of your code, such as missing validations in your models or having instance variables in your partials and the likes. Sadly, at the moment it’s not dealing with HAML templates yet, just ERB. (He’s looking for volunteers, by the way.;)) Here are the slides:
I can actually see myself using it.
And then Sven C. Koehler presented his somewhat irritatingly named1 yet spiffy Localmemcache. It’s a local, shared-memory-based, persistent key/value store, which looks pretty fascinating. I was a wee bit confused by it until it finally clicked — you wouldn’t be able to tell from its name, but it’s not related to memcached. Aha! It’s a C library with Ruby bindings which offers a more or less simple storage system (values are of the type String, but of course that would include Marshal‘ed data) and apparently blazingly fast — his benchmarks showed that Localmemcache is almost as fast as accessing native Ruby hashes. Its not for everyone —for example, as I understand, it requires a 64-bit Unix system— but it looks like a pretty interesting alternative to memcached for single-machine setups like, say, your single production machine or your local dev box. This should ease the issue of sharing data between different Ruby processes, for example. I’m definitely going to check that out.
Oh, and Peter Schrammel presented a concept for a truly private asset server. As I’m not entirely sure whether this is really public information yet, I’ll keep my yapper shut here. :)
Afterwards we all headed to the Park Café for conversations and drinks. All in all a very nice evening, even though I was still a bit groggy from the day before — the München Twittwoch. (Which reminds me, I should probably whip up a quick post about that as well. Eh.)
Again: my thanks go to the MoR organizers and all the people who showed up, I had a good time. :)
Hendrik moves to Brighton, UK. I still don’t have much to say about that, I am glad for him, but that doesn’t make me feel better about seeing my best friend moving away. :/ I can totally understand his notion, tho - I’ve been at the same point myself a few years ago - so it’s alright.
Well, we also still have the intertubes.
Anyways, he’s also looking for work. If you’re in or around Brighton and searching for a freelance Rails consulting/development ninja, you should at least look him up. :)
He builds "applications" or "sites" for them so-called "internets". Currently notable projects are TwerpScan and Ephemera, a Mac tool for Instapaper enthusiasts with ebook readers.
His hobbies include taming dolphins, riding lemurs and collecting spores, molds and fungus — the food of the future.
GP