summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgil Moeller <egil.moller@freecode.no>2010-04-03 19:11:39 +0200
committerEgil Moeller <egil.moller@freecode.no>2010-04-03 19:11:39 +0200
commit4b76ba7a6cbcb31ac5c9d0ec2d60e997f2dac6d1 (patch)
tree727f224057d0698480d8ae7c11a7f821c6d35b2e
parent9111bde776cc4f687a1720daafe326de63b09d6d (diff)
downloadetherpad-4b76ba7a6cbcb31ac5c9d0ec2d60e997f2dac6d1.tar.gz
etherpad-4b76ba7a6cbcb31ac5c9d0ec2d60e997f2dac6d1.tar.bz2
etherpad-4b76ba7a6cbcb31ac5c9d0ec2d60e997f2dac6d1.zip
Commented the tagBrowser a bit more
-rw-r--r--etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js b/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js
index 461f30a..eb42b10 100644
--- a/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js
+++ b/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js
@@ -45,6 +45,14 @@ function stringFormat(text, obj) {
return text;
}
+/* All these sql query functions both takes a querySql object as
+ * parameter and returns one. This object has two members - sql and
+ * params. Sql is a string of an sql table name or a subqyery in
+ * parens. The table pr subquery should have an ID column containing a
+ * PAD_ID.
+ */
+
+/* Filters pads by tags and anti-tags */
function getQueryToSql(tags, antiTags, querySql) {
var queryTable;
var queryParams;
@@ -100,6 +108,7 @@ function getQueryToSql(tags, antiTags, querySql) {
info["excepts"] = exceptArray.join(' ');
info["wheres"] = whereArray.length > 0 ? ' where ' + whereArray.join(' and ') : '';
+ /* Create a subselect from all the joins */
return {
sql: stringFormat(
'(select distinct ' +
@@ -114,6 +123,8 @@ function getQueryToSql(tags, antiTags, querySql) {
params: queryParams.concat(joinParamArray).concat(exceptParamArray)};
}
+/* Returns the sql to count the number of results from some other
+ * query. */
function nrSql(querySql) {
var queryTable;
var queryParams;
@@ -133,6 +144,9 @@ function nrSql(querySql) {
params: queryParams};
}
+/* Returns the sql to select the 10 best new tags to tack on to a
+ * query, that is, the tags that are closest to halving the result-set
+ * if tacked on. */
function newTagsSql(querySql) {
var queryTable;
var queryParams;
@@ -189,13 +203,14 @@ function onRequest() {
tags.push(query[i]);
}
+ /* Create the pad filter sql */
var querySql = getQueryToSql(tags.concat(['public']), antiTags);
- //log.info(querySql.sql);
+ /* Use the pad filter sql to figure out which tags to show in the tag browser this time. */
var queryNewTagsSql = newTagsSql(querySql);
var newTags = sqlobj.executeRaw(queryNewTagsSql.sql, queryNewTagsSql.params);
- var matchingPads;
+ /* Select the 10 last changed matching pads and some extra information on them. */
var sql = '' +
'select ' +
' m.id as ID, ' +
@@ -210,8 +225,7 @@ function onRequest() {
'order by ' +
' m.lastWriteTime desc ' +
'limit 10';
-
- matchingPads = sqlobj.executeRaw(sql, querySql.params);
+ var matchingPads = sqlobj.executeRaw(sql, querySql.params);
for (i = 0; i < matchingPads.length; i++) {
matchingPads[i].TAGS = matchingPads[i].TAGS.split('#');