From f509fce5e7c45299a7798ae1dc0d731eb1eaf1cb Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Mon, 12 Apr 2010 19:56:19 +0200 Subject: Moved some more stuff to the model --- .../twitterStyleTags/controllers/tagBrowser.js | 20 ++-------------- .../plugins/twitterStyleTags/models/tagQuery.js | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js b/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js index 838fb24..ac0d949 100644 --- a/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js +++ b/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js @@ -54,24 +54,8 @@ function onRequest() { var queryNewTagsSql = tagQuery.newTagsSql(querySql); var newTags = sqlobj.executeRaw(queryNewTagsSql.sql, queryNewTagsSql.params); - /* Select the 10 last changed matching pads and some extra information on them. Except the Pro Pads*/ - var sql = '' + - 'select ' + - ' m.id as ID, ' + - ' DATE_FORMAT(m.lastWriteTime, \'%a, %d %b %Y %H:%i:%s GMT\') as lastWriteTime, ' + - ' c.TAGS ' + - 'from ' + - querySql.sql + ' as q ' + - ' join PAD_SQLMETA as m on ' + - ' m.id = q.ID ' + - ' join PAD_TAG_CACHE as c on ' + - ' c.PAD_ID = q.ID ' + - 'where ' + - ' m.id NOT LIKE \'%$%\'' + - 'order by ' + - ' m.lastWriteTime desc ' + - 'limit 10'; - var matchingPads = sqlobj.executeRaw(sql, querySql.params); + padSql = tagQuery.padInfoSql(querySql, 10); + var matchingPads = sqlobj.executeRaw(padSql.sql, padSql.params); for (i = 0; i < matchingPads.length; i++) { matchingPads[i].TAGS = matchingPads[i].TAGS.split('#'); diff --git a/etherpad/src/plugins/twitterStyleTags/models/tagQuery.js b/etherpad/src/plugins/twitterStyleTags/models/tagQuery.js index a2e8374..8665b96 100644 --- a/etherpad/src/plugins/twitterStyleTags/models/tagQuery.js +++ b/etherpad/src/plugins/twitterStyleTags/models/tagQuery.js @@ -180,3 +180,31 @@ function newTagsSql(querySql) { '', info), params: queryNrParams.concat(queryParams)}; } + +/* Select the X last changed matching pads and some extra information + * on them. Except the Pro Pads*/ +function padInfoSql(querySql, limit, offset) { + var sql = '' + + 'select ' + + ' m.id as ID, ' + + ' DATE_FORMAT(m.lastWriteTime, \'%a, %d %b %Y %H:%i:%s GMT\') as lastWriteTime, ' + + ' c.TAGS ' + + 'from ' + + querySql.sql + ' as q ' + + ' join PAD_SQLMETA as m on ' + + ' m.id = q.ID ' + + ' join PAD_TAG_CACHE as c on ' + + ' c.PAD_ID = q.ID ' + + 'where ' + + ' m.id NOT LIKE \'%$%\'' + + 'order by ' + + ' m.lastWriteTime desc '; + if (limit != undefined) + sql += 'limit ' + limit + " "; + if (offset != undefined) + sql += 'offset ' + offset + " "; + return { + sql: sql, + params: querySql.params + }; +} -- cgit v1.2.3