Skip to content

Commit

Permalink
Merge pull request #30 from itmundi/feature/performance-improvements
Browse files Browse the repository at this point in the history
Feature/performance improvements
  • Loading branch information
bvangennep committed Feb 5, 2016
2 parents ea591e3 + 03c2395 commit 997ce54
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function registerSchematicFieldModels()

## Changelog

###3.1.2###
- Sections are not imported when nothing has changed
- Fields are not imported when nothing has changed
- Field import is repeated after everything else has been imported to make sure sources are set correctly

###3.1.1###
- Folders are now CamelCased to add support for case-sensitive systems and PSR-4 (thanks to @ostark and @ukautz)

Expand Down
8 changes: 8 additions & 0 deletions src/Services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ private function importFields(array $fieldDefinitions, FieldGroupModel $group)
foreach ($fieldDefinitions as $fieldHandle => $fieldDef) {
$field = $this->getFieldModel($fieldHandle);
$schematicFieldModel = $fieldFactory->build($fieldDef['type']);

if ($schematicFieldModel->getDefinition($field, true) === $fieldDef ) {
Craft::log(Craft::t('Skipping `{name}`, no changes detected', ['name' => $field->name]));
continue;
}

Craft::log(Craft::t('Importing `{name}`', ['name' => $fieldDef['name']]));

$schematicFieldModel->populate($fieldDef, $field, $fieldHandle, $group);
$this->saveFieldModel($field);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Services/Schematic.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private function importDataModel(Data $model, $force)
$sectionImportResult = Craft::app()->schematic_sections->import($model->getAttribute('sections'), $force);
$userGroupImportResult = Craft::app()->schematic_userGroups->import($model->getAttribute('userGroups'), $force);
$userImportResult = Craft::app()->schematic_users->import($model->getAttribute('users'), true);
$fieldImportResultFinal = Craft::app()->schematic_fields->import($model->getAttribute('fields'), $force);

// Element index settings are supported from Craft 2.5
if (version_compare(CRAFT_VERSION, '2.5', '>=')) {
Expand All @@ -116,6 +117,7 @@ private function importDataModel(Data $model, $force)
$result->consume($sectionImportResult);
$result->consume($userGroupImportResult);
$result->consume($userImportResult);
$result->consume($fieldImportResultFinal);

// Element index settings are supported from Craft 2.5
if (version_compare(CRAFT_VERSION, '2.5', '>=')) {
Expand Down
7 changes: 7 additions & 0 deletions src/Services/Sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public function import(array $sectionDefinitions, $force = false)

unset($sections[$sectionHandle]);

if($sectionDefinition === $this->getSectionDefinition($section, null)){
Craft::log(Craft::t('Skipping `{name}`, no changes detected', ['name' => $section->name]));
continue;
}

if (!array_key_exists('locales', $sectionDefinition)) {
$this->addError('`sections[handle].locales` must be defined');

Expand All @@ -170,6 +175,8 @@ public function import(array $sectionDefinitions, $force = false)
continue;
}

Craft::log(Craft::t('Importing section `{name}`', ['name' => $sectionDefinition['name']]));

$this->populateSection($section, $sectionDefinition, $sectionHandle);

// Create initial section record
Expand Down

0 comments on commit 997ce54

Please sign in to comment.