learningequality/ka-lite — pull request #749 by bcipolli (2013-09-21 19:32:35+00:00)
Title: Defer setting counter until sync

This is dependent on #748, and addresses #742. See #748 for similar background and motivations:

Issue:
* When saving a record under concurrency, a bottlenecks is that all records must wait for an exclusive lock on the local Device object, to both read and increment it's counter_position (ok, really that of the corresponding DeviceMetadata, but whatever dude! :) ).

Changes:
* For some objects (Facility*, *Log), defer setting counter_position until syncing occurs

Testing:
* Tested by running `generaterealdata`, and by syncing new data.

Review notes:
* @jamalex, if you could again give high- and mid-level comments, those would be most helpful to start with. Do you see any high-level issues with this idea? And do you see any issues with the overall approach/archiecture--defining a class that defers setting counters, then setting and saving counters in the sign_and_serialize method? Besides the fact that that method name got outdated within 2 hours? :P
* @gimick, could you benchmark this and leave some notes? Thanks!