From cced018825b64dc678964dd7afd918b1ee9228f5 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Dec 2018 18:48:33 +0000 Subject: [PATCH] Possibly fix a memory issue with large posts --- mod/display.php | 1 + src/Util/JsonLD.php | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mod/display.php b/mod/display.php index f4a09b74e0..2a4d2abf43 100644 --- a/mod/display.php +++ b/mod/display.php @@ -291,6 +291,7 @@ function display_content(App $a, $update = false, $update_uid = 0) $parent = Item::selectFirst(['uid'], ['uri' => $item_parent_uri, 'wall' => true]); if (DBA::isResult($parent)) { + $a->profile['uid'] = $parent['uid']; $a->profile['profile_uid'] = $parent['uid']; $is_remote_contact = Contact::isFollower(remote_user(), $a->profile['profile_uid']); } diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 78d81816e2..cd3a6ec270 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -93,8 +93,13 @@ class JsonLD 'dc' => (object)['@id' => 'http://purl.org/dc/terms/', '@type' => '@id'], 'toot' => (object)['@id' => 'http://joinmastodon.org/ns#', '@type' => '@id']]; - $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); + // Trying to avoid memory problems with large content fields + if (!empty($json['object']['source']['content'])) { + $content = $json['object']['source']['content']; + $json['object']['source']['content'] = ''; + } + $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); try { $compacted = jsonld_compact($jsonobj, $context); @@ -104,7 +109,13 @@ class JsonLD Logger::log('compacting error:' . print_r($e, true), Logger::DEBUG); } - return json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true); + $json = json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true); + + if (isset($json['as:object']['as:source']['as:content']) && !empty($content)) { + $json['as:object']['as:source']['as:content'] = $content; + } + + return $json; } /**