learningequality/ka-lite — pull request #748 by bcipolli (2013-09-21 17:12:45+00:00)
Title: Raspberry Pi: Signing when syncing, not when saving

Background:
Records are crytographically signed, to ensure that their contents were produced by the source (device) that they claim to have been, despite coming from a remote location.

Issue:
This signing process is computationally expensive. We operate on low-powered device (such as the Raspberry Pi), and this can take significant CPU time. With enough server activity, this can lead to client requests to update data being slow, failing, and ultimately data loss.

Changes:
* Central server saving remains untouched! Changes below are for distributed server only.
* Implement an abstract class which does not sign while saving, but rather assumes that it will be signed at the time of syncing
* Update code to sign unsigned records before syncing
* Use this DeferredSignSyncedModel base class for Facility* objects, and *Log objects.

Additional changes:
* Create an option in *Log save functions, to avoid updating user logs. This is generally useful, and something that can immediately be used in test scripts.
* A bit of renaming / cleanup on counter_position functions (more consistent naming and object scheme); this was done as part of trying to defer updating counters, and unnecessarily (but usefully) included here

Testing:
* Ran full test suite (and fixed old test failures (and a bug), separately)
* Ran manual syncing tests (which hits the automatic registration tests)
* Did NOT run tests on importing data at installation time.
* Did not test code on central server ... YET. Will update shortly!

Code review requests:
* @jamalex, most pressing need is to review the high- and mid-level designs:
* Any ideas for issues with deferring signing (besides those mentioned in #741)?
* Take a look at how I structured the code--making sure all code runs through common serialization code, to ensure signing. Thoughts?
* @gimick, can you benchmark this and see what performance is gained on the RPi?