I am developing a module which has to log and later playback all individual keystrokes in a form field. I would like to be able to store this in a database, and be able to retrieve this fast.
Typically it will be used to replay the path the user took to come to the finally submitted text.
I want to know if inserting a record for each keypress (perhaps grouping consecutive same strokes with a count for compression , albeit losing some timestamp info ?) is good,
CREATE TABLE `keystroke_log` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `keystroke` char(1) NOT NULL, `count` smallint(6) unsigned NOT NULL, `user_id` int(11) unsigned NOT NULL, 'form_field_id' int(11) unsigned NOT NULL, 'timestamp' timestamp NOT NULL default CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
or is it better to store all keystrokes in a single row as serialised JSON object with something like this ?
CREATE TABLE `keystroke_log` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `user_id` int(11) unsigned NOT NULL, `form_field_id` int(11) unsigned NOT NULL, `keystroke_dump` MEDIUMTEXT DEFAULT NULL, ) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 ENGINE=InnoDB DEFAULT CHARSET=utf8;
keystroke_dump JSON object would ideally contain timestamp and the actual UTF-8 stroke code
Is there any better way to store and retrieve this data ?
JSON in a relational DB is never a good idea, however the most common query will have to load the entire object anyway querying for full playback I am not sure if using a sql structure will result in significant performance loss?
preguntado el 28 de mayo de 14 a las 12:05