Jump to content

Page Save - Very Slow


Tom.
 Share

Recommended Posts

Hello, 

I've just launched a new site, however I'm finding that the page save function is performing really slow. We are pulling properties from Vebra (Jupix) and saving them as a page (so we can use PageArray functions such as filter and search).

$letType = array("0" => "Not Specified", "1" => "Long Term", "2" => "Short Term", "3" => "Student", "4" => "Commercial");
	$furnished = array("0" => "Furnished", "1" => "Part Furnished", "2" => "Un-Furnished", "3" => "Not Specified", "4" => "Furnished / Un-Furnished");
	$database = array("1" => "For Sale", "2" => "To Rent", "5" => "Commercial", "6" => "Commercial", "7" => "Commercial", "15" => "Developments", "41" => "To Rent", "118" => "Commercial");
	$qualifier = array("1" => "Price on Application", "2" => "Guide Price", "3" => "Fixed Price", "4" => "Offers in Excess of", "5" =>  "Offers in the Region of", "6" => "Sale by Tender", "7" => "From", "9" => "Shared Ownership", "10" => "Offers Over", "11" => "Part Buy Part Rent", "12" => "Shared Equity");
	
	$property = simplexml_load_string(vebraConnect($url));
	
	$id = $property->attributes()->id;
	if(wire('pages')->count("template=property, name=$id")) {
		$p = wire('pages')->get("template=property, name=$id");
	} else {
		$p = new Page();
		$p->template = 'property';
		$p->parent = wire('pages')->get('/properties/');
		$p->name = $id;
	}
	$p->of(false);
	$p->title = $property->address->display;
	
	$intDatabase = (int)$property->attributes()->database;
	if(array_key_exists($intDatabase, $database)) { $p->type = $database[$intDatabase]; $database = $database[$intDatabase]; }
	
	/*** CONTENT ***/
	$text = "";
	foreach($property->paragraphs->paragraph as $paragraph) {
		$text .= "<p>";
		if($paragraph->name->length > 0) $text .= "<strong>$paragraph->name</strong><br>";
		if($paragraph->dimensions->metric->length > 0) $dimensions = $paragraph->dimensions->metric;
		if($paragraph->dimensions->imperial->length > 0) $dimensions .= $paragraph->dimensions->imperial; 
		if($paragraph->dimensions->mixed->length > 0) $dimensions = $paragraph->dimensions->mixed;
		$text .= $dimensions ? "<em>$dimensions</em><br>" : "";
		$text .= "$paragraph->text</p>";
	}
	$p->content = $text;
	
	$bullets = "<ul>";
	foreach ($property->bullets->bullet as $bullet) { $bullets .= "<li>$bullet</li>"; }
	$bullets .= "</ul>";
	$p->info->bullets = $bullets;
	
	$p->info->excerpt = $property->description;
	
	/*** ADDRESS ***/
	$p->address->name = $property->address->name;
	$p->address->street = $property->address->street;
	$p->address->town = $property->address->town;
	$p->address->postcode = $property->address->postcode;
	$p->address->locality = $property->address->locality;
	$p->address->county = $property->address->county;
	$p->address->custom = $property->address->custom_location;
	$p->map->lat = (float)$property->latitude;
	$p->map->lng = (float)$property->longitude;
	$p->map->pitch = (float)$property->streetview->pov_pitch;
	$p->map->heading = (float)$property->streetview->pov_heading;
	
	/*** DETAILS ***/
	$p->property->type = $property->type;
	
	$status = (int)$property->web_status + 1;
	if($database=="For Sale") $p->sale_status = $status;
	else if($database=="To Rent") $p->let_status = $status;
	else if($database=="Commercial") {
		if($property->price->attributes()->rent == '') $p->sale_status = $status;
		else $p->let_status = $status;
	} else $p->sale_status = $status;
	
	$p->property->area = $property->area->max;
	$p->property->area_unit = $property->area->attributes()->unit;
	$p->property->landarea = $property->landarea->area;
	$p->property->landarea_unit = $property->landarea->attributes()->unit;
	$p->property->custom_status = $property->custom_status;
	
	$intLetType = (int)$property->rm_let_type_id;
	if(array_key_exists($intLetType, $letType)) $p->property->let_type = $letType[$intLetType];
	
	$intFurnished = (int)$property->furnished;
	if(array_key_exists($intFurnished, $furnished)) $p->property->furnished = $furnished[$intFurnished];
	
	$p->bedrooms = (int)$property->bedrooms;
	$p->receptions = (int)$property->receptions;
	$p->bathrooms = (int)$property->bathrooms;
	$p->parking = (int)$property->parking;
	
	/*** PRICE ***/
	$p->price = $property->price;
	$p->prices->rent_price = $property->price->attributes()->rent;
	$p->prices->currency = $property->price->attributes()->currency;
	$p->prices->price_qualifier = $property->price->attributes()->qualifier;
	
	$intQualifier = (int)$property->rm_qualifier;
	if(array_key_exists($intQualifier,$qualifier)) $p->prices->qualifier = $qualifier[$intQualifier];
	
	$p->prices->service_charge = $property->service_charge;
	$p->prices->rateable_value = $property->rateable_value;
	$p->prices->let_bond = $property->let_bond;
	$p->prices->ground_rent = html_entity_decode($property->groundrent);
	$p->prices->premium = $property->premium;
	$p->prices->fees = $property->rentalfees ." ". $property->lettingsfee;
	
	/*** DATA ***/
	$p->branch = wire('pages')->get("template=branch, name=".$property->attributes()->branchid);
	$p->dates->updated = strtotime((string)$changed);
	$p->dates->added = strtotime((string)$property->uploaded);
	$p->dates->available = strtotime((string)$property->available);
	
	$p->save();
	
	/*** MEDIA ***/
	if($p->images->count()) $p->images->removeAll();
	if($p->floorplans->count()) $p->floorplans->removeAll();
	if($p->pdfs->count()) $p->pdfs->removeAll();
	if($p->epc->count()) $p->epc->removeAll();
	
	foreach($property->files->file as $file) {
		$type = (int)$file->attributes()->type;
		$url = (string)$file->url;
		if($type == "0") $p->images->add($url);
		if($type == "2") $p->floorplans->add($url);
		if($type == "7") $p->pdfs->add($url);
		if($type == "9") $p->epc->add($url);
	}
	
	$p->save();

Often this will only return 1-2 properties as it only get's the updated one. However the website will come to a crunch when this function is fired. 

Is there anything I can do to speed this up?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...