Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F803805
D396.id1057.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 8:58 AM
Size
4 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 8:58 AM (10 h, 22 m)
Engine
blob
Format
Raw Data
Handle
576529
Attached To
D396: INP-1797 - Speed up formatter class access from "kDBItem"
D396.id1057.diff
View Options
Index: branches/5.2.x/core/kernel/db/dbitem.php
===================================================================
--- branches/5.2.x/core/kernel/db/dbitem.php
+++ branches/5.2.x/core/kernel/db/dbitem.php
@@ -127,8 +127,7 @@
$formatter = $this->GetFieldOption($field_name, 'formatter');
if ( $formatter ) {
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject($formatter);
+ $formatter = $this->getFormatter($formatter);
if ( $formatter instanceof kMultiLanguage && strpos((string)$format, 'no_default') === false ) {
$format = rtrim('no_default;' . $format, ';');
@@ -187,12 +186,14 @@
$parsed = NULL;
}
- // kFormatter is always used, to make sure, that numeric value is converted to normal representation
- // according to regional format, even when formatter is not set (try seting format to 1.234,56 to understand why)
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject(isset($options['formatter']) ? $options['formatter'] : 'kFormatter');
-
- $parsed = $formatter->Parse($value, $name, $this);
+ /*
+ * kFormatter is always used, to make sure, that numeric value is converted to normal representation
+ * according to regional format, even when formatter is not set (try setting format to 1.234,56 to
+ * understand why).
+ */
+ $parsed = $this
+ ->getFormatter(isset($options['formatter']) ? $options['formatter'] : 'kFormatter')
+ ->Parse($value, $name, $this);
$this->SetDBField($name,$parsed);
}
@@ -543,10 +544,9 @@
foreach ($this->Fields as $field => $options) {
if ( isset($options['formatter']) ) {
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject($options['formatter']);
-
- $formatter->UpdateMasterFields($field, $this->GetDBField($field), $options, $this);
+ $this
+ ->getFormatter($options['formatter'])
+ ->UpdateMasterFields($field, $this->GetDBField($field), $options, $this);
}
}
}
@@ -1565,7 +1565,7 @@
$cdata->SetDBField('ResourceId', $resource_id);
/** @var kMultiLanguage $ml_formatter */
- $ml_formatter = $this->Application->recallObject('kMultiLanguage');
+ $ml_formatter = $this->getFormatter('kMultiLanguage');
/** @var kMultiLanguageHelper $ml_helper */
$ml_helper = $this->Application->recallObject('kMultiLanguageHelper');
Index: branches/5.2.x/core/kernel/kbase.php
===================================================================
--- branches/5.2.x/core/kernel/kbase.php
+++ branches/5.2.x/core/kernel/kbase.php
@@ -266,6 +266,13 @@
protected $parentEvent = null;
/**
+ * Formatters cache.
+ *
+ * @var kFormatter[]
+ */
+ static private $_formattersCache = array();
+
+ /**
* Sets new parent event to the object
*
* @param kEvent $event
@@ -883,10 +890,7 @@
if ( $formatter_class ) {
$value = ($formatter_class == 'kMultiLanguage') && !preg_match('/^l[0-9]+_/', $name) ? '' : $this->GetDBField($name);
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject($formatter_class);
-
- return $formatter->Format($value, $name, $this, $format);
+ return $this->getFormatter($formatter_class)->Format($value, $name, $this, $format);
}
return $this->GetDBField($name);
@@ -933,10 +937,9 @@
foreach ($fields as $field) {
if ( isset($this->Fields[$field]['formatter']) ) {
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject($this->Fields[$field]['formatter']);
-
- $formatter->UpdateSubFields($field, $this->GetDBField($field), $this->Fields[$field], $this);
+ $this
+ ->getFormatter($this->Fields[$field]['formatter'])
+ ->UpdateSubFields($field, $this->GetDBField($field), $this->Fields[$field], $this);
}
}
}
@@ -955,11 +958,26 @@
continue;
}
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject( $this->Fields[$field_name]['formatter'] );
+ $this
+ ->getFormatter($this->Fields[$field_name]['formatter'])
+ ->PrepareOptions($field_name, $this->Fields[$field_name], $this);
+ }
+ }
- $formatter->PrepareOptions($field_name, $this->Fields[$field_name], $this);
+ /**
+ * Returns formatter.
+ *
+ * @param string $name Name.
+ *
+ * @return kFormatter
+ */
+ protected function getFormatter($name)
+ {
+ if ( !isset(self::$_formattersCache[$name]) ) {
+ self::$_formattersCache[$name] = $this->Application->recallObject($name);
}
+
+ return self::$_formattersCache[$name];
}
/**
Event Timeline
Log In to Comment