From eb22d2d2401293ec87e9fa2c2e7fb053d9780dfd Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 5 Jan 2010 15:04:08 -0800 Subject: Ticket 2135: trim overlong repeats with ellipsis rather than failing. In web interface and retweet/repeat API we show the original untrimmed text, but some back-compat API messages will still show the trimmed 'RT' version. This matches Twitter's behavior on overlong retweets, though we're outputting the RT version in more API results than they do. --- classes/Notice.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 93e94230d..6d75cbcad 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1366,12 +1366,21 @@ class Notice extends Memcached_DataObject { $author = Profile::staticGet('id', $this->profile_id); - // FIXME: truncate on long repeats...? - $content = sprintf(_('RT @%1$s %2$s'), $author->nickname, $this->content); + $maxlen = common_config('site', 'textlimit'); + if (mb_strlen($content) > $maxlen) { + // Web interface and current Twitter API clients will + // pull the original notice's text, but some older + // clients and RSS/Atom feeds will see this trimmed text. + // + // Unfortunately this is likely to lose tags or URLs + // at the end of long notices. + $content = mb_substr($content, 0, $maxlen - 4) . ' ...'; + } + return self::saveNew($repeater_id, $content, $source, array('repeat_of' => $this->id)); } -- cgit v1.2.3-54-g00ecf From bbbec435b02340b38aac8facf90f43868e2af144 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 5 Jan 2010 16:15:12 -0800 Subject: Fix for overlong RT trimming: don't trim if textlimit is 0 (unlimited) --- classes/Notice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 6d75cbcad..c2ff7fd09 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1371,7 +1371,7 @@ class Notice extends Memcached_DataObject $this->content); $maxlen = common_config('site', 'textlimit'); - if (mb_strlen($content) > $maxlen) { + if ($maxlen > 0 && mb_strlen($content) > $maxlen) { // Web interface and current Twitter API clients will // pull the original notice's text, but some older // clients and RSS/Atom feeds will see this trimmed text. -- cgit v1.2.3-54-g00ecf From 9d3893255a77ee6c6cf1ab861d0da55ecbadbecc Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 10 Jan 2010 12:31:43 -0800 Subject: don't put Users with object IDs in the cache, and don't fetch them --- classes/Memcached_DataObject.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index ca360d411..21f6781c2 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -68,7 +68,7 @@ class Memcached_DataObject extends DB_DataObject // Clear this out so we don't accidentally break global // state in *this* process. $this->_DB_resultid = null; - + // We don't have any local DBO refs, so clear these out. $this->_link_loaded = false; } @@ -171,7 +171,16 @@ class Memcached_DataObject extends DB_DataObject if (!$c) { return false; } else { - return $c->get(Memcached_DataObject::cacheKey($cls, $k, $v)); + $obj = $c->get(Memcached_DataObject::cacheKey($cls, $k, $v)); + if (0 == strcasecmp($cls, 'User')) { + // Special case for User + if (is_object($obj->id)) { + common_log(LOG_ERR, "User " . $obj->nickname . " was cached with User as ID; deleting"); + $c->delete(Memcached_DataObject::cacheKey($cls, $k, $v)); + return false; + } + } + return $obj; } } @@ -190,6 +199,12 @@ class Memcached_DataObject extends DB_DataObject $c = $this->memcache(); if (!$c) { return false; + } else if ($this->tableName() == 'user' && is_object($this->id)) { + // Special case for User bug + $e = new Exception(); + common_log(LOG_ERR, __METHOD__ . ' caching user with User object as ID ' . + str_replace("\n", " ", $e->getTraceAsString())); + return false; } else { $pkey = array(); $pval = array(); -- cgit v1.2.3-54-g00ecf From f463329b9a5575856757ae8879e4cc11400d50a2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 10 Jan 2010 13:18:53 -0800 Subject: check before inserting File_oembed and File_thumbnail --- classes/File.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'classes') diff --git a/classes/File.php b/classes/File.php index e04a9d525..03d9ca6f0 100644 --- a/classes/File.php +++ b/classes/File.php @@ -80,7 +80,14 @@ class File extends Memcached_DataObject if (isset($redir_data['type']) && (('text/html' === substr($redir_data['type'], 0, 9) || 'application/xhtml+xml' === substr($redir_data['type'], 0, 21))) && ($oembed_data = File_oembed::_getOembed($given_url))) { + + $fo = File_oembed::staticGet('file_id', $file_id); + + if (empty($fo)) { File_oembed::saveNew($oembed_data, $file_id); + } else { + common_log(LOG_WARNING, "Strangely, a File_oembed object exists for new file $file_id", __FILE__); + } } return $x; } -- cgit v1.2.3-54-g00ecf From 2e42d3336af659ef76b2a9ade9cec099ba9ff521 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 10 Jan 2010 13:25:16 -0800 Subject: check before saving a thumbnail --- classes/File_oembed.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/File_oembed.php b/classes/File_oembed.php index e41ccfd09..11f160718 100644 --- a/classes/File_oembed.php +++ b/classes/File_oembed.php @@ -115,7 +115,13 @@ class File_oembed extends Memcached_DataObject } $file_oembed->insert(); if (!empty($data->thumbnail_url)) { - File_thumbnail::saveNew($data, $file_id); + $ft = File_thumbnail::staticGet('file_id', $file_id); + if (!empty($ft)) { + common_log(LOG_WARNING, "Strangely, a File_thumbnail object exists for new file $file_id", + __FILE__); + } else { + File_thumbnail::saveNew($data, $file_id); + } } } } -- cgit v1.2.3-54-g00ecf