try to reduce memory usage in FOAF output

This commit is contained in:
Evan Prodromou 2009-04-03 14:18:29 -04:00
parent 45d5205505
commit 860d7f79a9
1 changed files with 34 additions and 10 deletions

View File

@ -139,20 +139,30 @@ class FoafAction extends Action
if ($sub->find()) { if ($sub->find()) {
while ($sub->fetch()) { while ($sub->fetch()) {
if ($sub->token) { if (!empty($sub->token)) {
$other = Remote_profile::staticGet('id', $sub->subscribed); $other = Remote_profile::staticGet('id', $sub->subscribed);
} else { } else {
$other = User::staticGet('id', $sub->subscribed); $other = User::staticGet('id', $sub->subscribed);
} }
if (!$other) { if (empty($other)) {
common_debug('Got a bad subscription: '.print_r($sub,true)); common_debug('Got a bad subscription: '.print_r($sub,true));
continue; continue;
} }
$this->element('knows', array('rdf:resource' => $other->uri)); $this->element('knows', array('rdf:resource' => $other->uri));
$person[$other->uri] = array(LISTENEE, $other); $person[$other->uri] = array(LISTENEE,
$other->id,
$other->nickname,
(empty($sub->token)) ? 'User' : 'Remote_profile');
$other->free();
$other = null;
unset($other);
} }
} }
$sub->free();
$sub = null;
unset($sub);
// Get people who subscribe to user // Get people who subscribe to user
$sub = new Subscription(); $sub = new Subscription();
@ -173,24 +183,35 @@ class FoafAction extends Action
if (array_key_exists($other->uri, $person)) { if (array_key_exists($other->uri, $person)) {
$person[$other->uri][0] = BOTH; $person[$other->uri][0] = BOTH;
} else { } else {
$person[$other->uri] = array(LISTENER, $other); $person[$other->uri] = array(LISTENER,
} $other->id,
$other->nickname,
(empty($sub->token)) ? 'User' : 'Remote_profile');
}
$other->free();
$other = null;
unset($other);
} }
} }
$sub->free();
$sub = null;
unset($sub);
$this->elementEnd('Person'); $this->elementEnd('Person');
foreach ($person as $uri => $p) { foreach ($person as $uri => $p) {
$foaf_url = null; $foaf_url = null;
if ($p[1] instanceof User) { list($type, $id, $nickname, $cls) = $p;
$foaf_url = common_local_url('foaf', array('nickname' => $p[1]->nickname)); if ($cls == 'User') {
$foaf_url = common_local_url('foaf', array('nickname' => $nickname));
} }
$this->profile = Profile::staticGet($p[1]->id); $profile = Profile::staticGet($id);
$this->elementStart('Person', array('rdf:about' => $uri)); $this->elementStart('Person', array('rdf:about' => $uri));
if ($p[0] == LISTENER || $p[0] == BOTH) { if ($type == LISTENER || $type == BOTH) {
$this->element('knows', array('rdf:resource' => $this->user->uri)); $this->element('knows', array('rdf:resource' => $this->user->uri));
} }
$this->showMicrobloggingAccount($this->profile, ($p[1] instanceof User) ? $this->showMicrobloggingAccount($profile, ($cls == 'User') ?
common_root_url() : null); common_root_url() : null);
if ($foaf_url) { if ($foaf_url) {
$this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url)); $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
@ -199,6 +220,9 @@ class FoafAction extends Action
if ($foaf_url) { if ($foaf_url) {
$this->showPpd($foaf_url, $uri); $this->showPpd($foaf_url, $uri);
} }
$profile->free();
$profile = null;
unset($profile);
} }
$this->elementEnd('rdf:RDF'); $this->elementEnd('rdf:RDF');