Skip to content

Instantly share code, notes, and snippets.

@sesam
Created April 10, 2010 22:55
Show Gist options
  • Save sesam/362352 to your computer and use it in GitHub Desktop.
Save sesam/362352 to your computer and use it in GitHub Desktop.
diff --git a/etherpad/src/plugins/twitterStyleTags/hooks.js b/etherpad/src/plugins/twitterStyleTags/hooks.js
index 003bc32..e49439e 100644
--- a/etherpad/src/plugins/twitterStyleTags/hooks.js
+++ b/etherpad/src/plugins/twitterStyleTags/hooks.js
@@ -10,7 +10,8 @@ function handlePath() {
function padModelWriteToDB(args) {
/* Update tags for the pad */
- var new_tags = args.pad.text().match(new RegExp("#[^,#=!\\s][^,#=!\\s]*", "g"));
+ var atext = args.pad.text();
+ var new_tags = atext.match(new RegExp("#[^,#=!\\s][^,#=!\\s]*", "g"));
if (new_tags == null) new_tags = new Array();
for (i = 0; i < new_tags.length; i++)
new_tags[i] = new_tags[i].substring(1);
@@ -33,6 +34,7 @@ function padModelWriteToDB(args) {
else
sqlobj.insert("PAD_TAG_CACHE", {PAD_ID: args.padId, TAGS: new_tags.join('#')});
+ /* Remove and recreate all involved tags, to make sure no tags are left behind? */
sqlobj.deleteRows("PAD_TAG", {PAD_ID: args.padId});
for (i = 0; i < new_tags.length; i++) {
@@ -44,4 +46,31 @@ function padModelWriteToDB(args) {
sqlobj.insert("PAD_TAG", {PAD_ID: args.padId, TAG_ID: tag_row['ID']});
}
}
+
+
+ /* Update title cache for the pad */
+ var title_text = atext.replace(/(^\s+|\s+$)/g,'');
+ var title_rows = title_text.split(/[\n\r]+/); /* linefeed issues? */
+ var title;
+ for (var i=0; i<title_rows.length; i++) {
+ var textrow = title_rows[i].length;
+ if (textrow.length) {
+ title = textrow;
+ if (title.length>80-3) title = title.substring(0,80-1-3)+'...';
+ break;
+ }
+ }
+
+ var old_title_row = sqlobj.selectSingle("PAD_TITLE_CACHE", { PAD_ID: args.padId });
+ var old_title_str = '';
+ if (old_title_row !== null)
+ old_title_str = old_title_row['TITLE'];
+ if (old_title_str != title) {
+ /*log.info({message: 'Updating cached title', title:title, old_title_str:old_title_str});*/
+ if (old_title_row)
+ sqlobj.update("PAD_TITLE_CACHE", {PAD_ID: args.padId }, {TITLE: title});
+ else
+ sqlobj.insert("PAD_TITLE_CACHE", {PAD_ID: args.padId, TITLE: title});
+ }
+
}
\ No newline at end of file
diff --git a/etherpad/src/plugins/twitterStyleTags/main.js b/etherpad/src/plugins/twitterStyleTags/main.js
index 34d5d85..a903b42 100644
--- a/etherpad/src/plugins/twitterStyleTags/main.js
+++ b/etherpad/src/plugins/twitterStyleTags/main.js
@@ -35,6 +35,11 @@ function install() {
TAGS: 'varchar(1024) collate utf8_bin not null',
});
+ sqlobj.createTable('PAD_TITLE_CACHE', {
+ PAD_ID: 'varchar(128) character set utf8 collate utf8_bin unique not null references PAD_META(ID)',
+ TITLE: 'varchar(80) collate utf8_bin not null',
+ });
+
}
function uninstall() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment