Skip to content

Commit 67250b0

Browse files
REFACTORING: Storing user activity
According to CouchDB documentation, Batch Mode Write improves performances and is ideal for applications such as log data. We leave the 9 seconds delay introduced in commit aeabdb9
1 parent de0a8c9 commit 67250b0

5 files changed

Lines changed: 37 additions & 33 deletions

File tree

app/_attachments/log.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,36 @@ function updateTooltip(id, content) {
108108
.tooltip({ trigger: 'hover', offset: "0, 8" });
109109
}
110110

111+
function track_memo(user, memoid) {
112+
$.ajax({
113+
url: '../'+user,
114+
type: 'GET'
115+
}).done(function(u){
116+
u = JSON.parse(u);
117+
if (!u.contributors) u.contributors = [user]
118+
if (!u.activity) u.activity = []
119+
var obj = {
120+
'doc': memoid,
121+
'date': new Date().toJSON()
122+
};
123+
var i = -1, j = 0;
124+
for (j = 0; j < u.activity.length; j++) {
125+
if (u.activity[j].doc === memoid) i = j
126+
}
127+
if (i > -1) {
128+
u.activity.splice(i, 1, obj)
129+
} else {
130+
u.activity.push(obj)
131+
}
132+
$.ajax({
133+
url: '../'+user+'?batch=ok',
134+
type: 'PUT',
135+
contentType: 'application/json',
136+
data: JSON.stringify(u),
137+
})
138+
})
139+
}
140+
111141
function createUserDoc(user, sponsor, success, error) {
112142
$.ajax({
113143
url: relpath+'userfullname/'+fullname,

app/lib/shared.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,33 +300,26 @@ var shared = {
300300
{{/list}}\
301301
if ('{{logged}}') user = '{{logged}}';\
302302
function track(memo) {\
303+
{{^list}}track_memo(user, memo){{/list}}\
304+
{{#list}}\
303305
$.ajax({\
304-
{{^list}}\
305-
url: '../track_memo/'+user,\
306-
{{/list}}\
307-
{{#list}}\
308306
url: '../save_diary_order/'+user,\
309-
{{/list}}\
310307
type: 'PUT',\
311308
contentType: 'application/json',\
312-
{{^list}}\
313-
data: memo,\
314-
{{/list}}\
315-
{{#list}}\
316309
data: JSON.stringify({\
317310
'diary': '{{diary}}',\
318311
'by': memo\
319312
}),\
320-
{{/list}}\
321-
}).done({{#list}}reload{{/list}})\
322-
.fail({{#list}}function(data){$('#storing_fullname_dialog').modal('show')}{{/list}});\
313+
}).done(reload)\
314+
.fail(function(data){$('#storing_fullname_dialog').modal('show')});\
315+
{{/list}}\
323316
}",
324317
render: "\
325318
render();\
326319
{{^statements}}\
327320
{{^link}}if (($('#groundings>li[id]').length > 1) || ('{{type}}' == 'coding' && $('#groundings li').first().find('.preview a').length > 1))\
328321
$('#remove_grounding_btn').removeClass('d-none');{{/link}}\
329-
{{#type}}{{#logged}}setTimeout(function() {track('{{_id}}')}, 9000);{{/logged}}{{/type}}\
322+
{{#type}}{{#logged}}track('{{_id}}'){{/logged}}{{/type}}\
330323
{{/statements}}\
331324
"
332325
};

app/rewrites.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ function(req2) {
310310
case 'rename_diagram':
311311
case 'adapt_diagram':
312312
case 'adapt_graph':
313-
case 'track_memo':
314313
case 'modify_rights':
315314
case 'reader_unsubscribe':
316315
case 'username':

app/shows/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function(o, req) {
77
return {
88
body: JSON.stringify({
99
service: 'Cassandre',
10-
revision: '3.22.09.06',
10+
revision: '3.22.09.11',
1111
update_seq: req.info.update_seq
1212
})
1313
}

app/updates/track_memo.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)