SlideShare a Scribd company logo
1 of 25
Field Storage API
FieldableEntityStorageController
CCK

Artem Sylchuk, IntenetDevels
About me:
Drupal developer since 2010
Story 1
Save 1 000 000 nodes in 1 second
XHProf

~ 4 seconds for 50 nodes.
~ 50% of the database time.
~ 100% of the fields update time.
Anatomy of the node_save()
field_attach_presave('node', $node);
module_invoke_all('node_presave', $node);
module_invoke_all('entity_presave', $node, 'node');

drupal_write_record('node', $node);

You need all this if you want own fieldable entity.
Procedural code is simple, isn’t it?

_node_save_revision($node, $user->uid);
node_invoke($node, $op); // $op == ‘update’ || $op == ‘insert’

-------------------------------------------------------------------------------------------

// Save fields.$function = "field_attach_$op";$function('node', $node); // field_attatch_update ||
field_attach_insert
module_invoke($storage_info['module'], 'field_storage_write', …..);

field_sql_storage_field_storage_write()
Long time ago in a galaxy far away...

-------------------------------------------------------------------------------------------

module_invoke_all('node_' . $op, $node);module_invoke_all('entity_' . $op, $node, 'node');
node_access_acquire_grants($node, $delete);
entity_get_controller('node')->resetCache(array($node->nid));
Field data field & field data revision
foreach ($field['columns'] as $column => $attributes) {
$columns[] = _field_sql_storage_columnname ($field_name, $column);

}
$query = db_insert($table_name)->fields($columns);
$revision_query = db_insert($revision_name)->fields($columns);
foreach ($field_languages as $langcode) {
$items = (array) $entity->{$field_name}[$langcode];
$delta_count = 0;
foreach ($items as $delta => $item) {
// We now know we have someting to insert.

$do_insert = TRUE;

$record = array(

Function loops for all fields in the entity end performs
Delete/Insert

'entity_type' => $entity_type,
'entity_id' => $id,
'revision_id' => $vid,
'bundle' => $bundle,
'delta' => $delta,
'language' => $langcode,

);
foreach ($field['columns'] as $column => $attributes) {
$record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;

}
$query->values($record);
if (isset($vid)) {
$revision_query->values($record);

}
if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) {
break;

}
}

}
// Execute the query if we have values to insert.
$query->execute();
$revision_query->execute();

}
}

if ($do_insert) {
Can I haz some SQLs?
Story 2
Back in my day...
Content Construction Kit: Drupal 6
Drupal 7
Why, Dries, why?
https://drupal.org/node/1035804#comment-6860324

“This option is the one that "makes sense" to non-Drupal coders who have
written some PHP by hand before now and think they know their way
around making their own database schema. It's not wrong if you are building
one thing once..
Nowadays however, if you choose to use the Drupal framework and build reusable tools,

•
•
•

All Drupal text entity fields must be translatable (non-negotiable)
All Drupal entity fields must be revisionable (non-negotiable)
All Drupal entity fields must support being multiple (negotiable, but it's
easier to allow them to be multiple as it's free to do so)

If the problem *you* are solving today doesn't actually seem to need all those
features right now, that's quite likely. You may also know that you'll never
need to do translations, and that a number of your values aren't going to
need to be multiple (according to todays business rules anyway). Next year
you'll probably wish you'd supported revisions, but that's next year.”

© dman
«I don’t need this»

•

Field SQL Norevisions:
https://drupal.org/project/field_sql_norevisions

•

MongoDB:
https://drupal.org/project/mongodb

•

Per-Bundle Storage:
https://drupal.org/project/pbs

•

EntityFieldQuery Views Backend:
https://drupal.org/project/efq_views

•

Own storage?
Imagine
1. Storage level caching
2. Multi-update: node_save_multiple

3. Check if field was changed before
performing a query

4. Simple storage without delta and language
columns.
5. What else?
I’ll write own storage with a….
1. hook_field_storage_info().

2. hook_field_storage_details().
3. hook_field_storage_create_field().
4. hook_field_storage_update_field().
5. hook_field_storage_delete_field().

6. hook_field_storage_load().
7. hook_field_storage_write().
8. hook_entity_query_alter().
9. hook_field_storage_query().

10. hook_field_attach_rename_bundle().
11. hook_entity_insert().
12. hook_entity_update().
13. hook_field_attach_delete().
Let’s do it quick
http://posulliv.github.io/2013/01/07/bench-field-storage/

innodb_flush_log_at_trx_commit=0
innodb_doublewrite=0
log-bin=0
innodb_support_xa=0
innodb_buffer_pool_size=6G
innodb_log_file_size=512M
Curiosity is a way
forward
Drupal 8
https://drupal.org/node/1497374
extends DatabaseStorageControllerNG
which extends DatabaseStorageController
which extends FieldableEntityStorageControllerBase
which implements FieldableEntityStorageControllerInterface
FieldableEntityStorageControllerBase
What’s next?
https://drupal.org/node/2083451
Reconsider the separate field revision data tables
https://drupal.org/node/2068325
[META] Convert entity SQL queries to the Entity Query API
Questions?
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageControllerInterface

More Related Content

What's hot

Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMR
Shinji Tanaka
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
Mohammad Qureshi
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
Introduction to asynchronous DB access using Node.js and MongoDB
Introduction to asynchronous DB access using Node.js and MongoDBIntroduction to asynchronous DB access using Node.js and MongoDB
Introduction to asynchronous DB access using Node.js and MongoDB
Adrien Joly
 

What's hot (20)

Microsoft HPC - Kivanc Ozuolmez - Public Content
Microsoft HPC - Kivanc Ozuolmez - Public ContentMicrosoft HPC - Kivanc Ozuolmez - Public Content
Microsoft HPC - Kivanc Ozuolmez - Public Content
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMR
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node Driver
 
Dmp hadoop getting_start
Dmp hadoop getting_startDmp hadoop getting_start
Dmp hadoop getting_start
 
Node.js
Node.jsNode.js
Node.js
 
Joblib for cloud computing
Joblib for cloud computingJoblib for cloud computing
Joblib for cloud computing
 
Swift after one week of coding
Swift after one week of codingSwift after one week of coding
Swift after one week of coding
 
Introduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter Halligan
 
Streams
StreamsStreams
Streams
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Scylla Summit 2022: ScyllaDB Embraces Wasm
Scylla Summit 2022: ScyllaDB Embraces WasmScylla Summit 2022: ScyllaDB Embraces Wasm
Scylla Summit 2022: ScyllaDB Embraces Wasm
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
Cassandra Summit 2014: Reading Cassandra SSTables Directly for Offline Data A...
Cassandra Summit 2014: Reading Cassandra SSTables Directly for Offline Data A...Cassandra Summit 2014: Reading Cassandra SSTables Directly for Offline Data A...
Cassandra Summit 2014: Reading Cassandra SSTables Directly for Offline Data A...
 
Introduction to asynchronous DB access using Node.js and MongoDB
Introduction to asynchronous DB access using Node.js and MongoDBIntroduction to asynchronous DB access using Node.js and MongoDB
Introduction to asynchronous DB access using Node.js and MongoDB
 
Ansible @ WebElement 2015
Ansible @ WebElement 2015Ansible @ WebElement 2015
Ansible @ WebElement 2015
 
Object Oriented Javascript
Object Oriented JavascriptObject Oriented Javascript
Object Oriented Javascript
 

Similar to Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageControllerInterface

Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
Buildingsocialanalyticstoolwithmongodb
MongoDB APAC
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0
Quang Ngoc
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
Tomas Cervenka
 
OpenERP Technical Memento
OpenERP Technical MementoOpenERP Technical Memento
OpenERP Technical Memento
Odoo
 
Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001
jucaab
 

Similar to Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageControllerInterface (20)

NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
Buildingsocialanalyticstoolwithmongodb
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
 
Debugging Drupal - How to Debug your Drupal Application
Debugging Drupal - How to Debug your Drupal ApplicationDebugging Drupal - How to Debug your Drupal Application
Debugging Drupal - How to Debug your Drupal Application
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0
 
Working with LoopBack Models
Working with LoopBack ModelsWorking with LoopBack Models
Working with LoopBack Models
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools
 
Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Gary Fowler [InfluxData] | InfluxDB Scripting Languages | InfluxDays 2022
Gary Fowler [InfluxData] | InfluxDB Scripting Languages | InfluxDays 2022Gary Fowler [InfluxData] | InfluxDB Scripting Languages | InfluxDays 2022
Gary Fowler [InfluxData] | InfluxDB Scripting Languages | InfluxDays 2022
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
OpenERP Technical Memento
OpenERP Technical MementoOpenERP Technical Memento
OpenERP Technical Memento
 
Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4
 
Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001
 

More from LEDC 2016

Анатолій Поляков — Subdomains everywhere
Анатолій Поляков — Subdomains everywhereАнатолій Поляков — Subdomains everywhere
Анатолій Поляков — Subdomains everywhere
LEDC 2016
 

More from LEDC 2016 (20)

A. Postnikov & P. Mahrinsky — Drupal Community — це ми
A. Postnikov & P. Mahrinsky — Drupal Community — це миA. Postnikov & P. Mahrinsky — Drupal Community — це ми
A. Postnikov & P. Mahrinsky — Drupal Community — це ми
 
Слава Мережко — Практикум: "Як ростити розробників"
Слава Мережко — Практикум: "Як ростити розробників"Слава Мережко — Практикум: "Як ростити розробників"
Слава Мережко — Практикум: "Як ростити розробників"
 
Генадій Колтун — Комунізм наступає: що будемо робити, коли машини навчаться п...
Генадій Колтун — Комунізм наступає: що будемо робити, коли машини навчаться п...Генадій Колтун — Комунізм наступає: що будемо робити, коли машини навчаться п...
Генадій Колтун — Комунізм наступає: що будемо робити, коли машини навчаться п...
 
Олексій Калініченко — Configuration Management in Drupal8
Олексій Калініченко — Configuration Management in Drupal8Олексій Калініченко — Configuration Management in Drupal8
Олексій Калініченко — Configuration Management in Drupal8
 
Олександр Лінивий — Multisite platform with continuous delivery process for m...
Олександр Лінивий — Multisite platform with continuous delivery process for m...Олександр Лінивий — Multisite platform with continuous delivery process for m...
Олександр Лінивий — Multisite platform with continuous delivery process for m...
 
Андрій Юн — Воркшоп "Docker use cases for developers"
Андрій Юн — Воркшоп "Docker use cases for developers"Андрій Юн — Воркшоп "Docker use cases for developers"
Андрій Юн — Воркшоп "Docker use cases for developers"
 
Андрій Поданенко — Воркшоп "Розвертання CIBox"
Андрій Поданенко — Воркшоп "Розвертання CIBox"Андрій Поданенко — Воркшоп "Розвертання CIBox"
Андрій Поданенко — Воркшоп "Розвертання CIBox"
 
Юрій Герасімов — Editorial experience in Drupal8
Юрій Герасімов — Editorial experience in Drupal8Юрій Герасімов — Editorial experience in Drupal8
Юрій Герасімов — Editorial experience in Drupal8
 
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
 
Тарас Кирилюк — Docker basics. How-to for Drupal developers
Тарас Кирилюк — Docker basics. How-to for Drupal developersТарас Кирилюк — Docker basics. How-to for Drupal developers
Тарас Кирилюк — Docker basics. How-to for Drupal developers
 
Тарас Круц — Open Social: brand new Drupal 8 distro for building social netwo...
Тарас Круц — Open Social: brand new Drupal 8 distro for building social netwo...Тарас Круц — Open Social: brand new Drupal 8 distro for building social netwo...
Тарас Круц — Open Social: brand new Drupal 8 distro for building social netwo...
 
Ігор Карпиленко — PHPStorm for drupal developer
Ігор Карпиленко — PHPStorm for drupal developerІгор Карпиленко — PHPStorm for drupal developer
Ігор Карпиленко — PHPStorm for drupal developer
 
Олександр Щедров — Build your application in seconds and optimize workflow as...
Олександр Щедров — Build your application in seconds and optimize workflow as...Олександр Щедров — Build your application in seconds and optimize workflow as...
Олександр Щедров — Build your application in seconds and optimize workflow as...
 
Анатолій Поляков — Subdomains everywhere
Анатолій Поляков — Subdomains everywhereАнатолій Поляков — Subdomains everywhere
Анатолій Поляков — Subdomains everywhere
 
Артем Доценко — Deploy Plus. Better UI and more control for deploy module
Артем Доценко — Deploy Plus. Better UI and more control for deploy moduleАртем Доценко — Deploy Plus. Better UI and more control for deploy module
Артем Доценко — Deploy Plus. Better UI and more control for deploy module
 
Сергій Бондаренко — Тестування Drupal сайтiв з допогою TqExtension
Сергій Бондаренко — Тестування Drupal сайтiв з допогою TqExtensionСергій Бондаренко — Тестування Drupal сайтiв з допогою TqExtension
Сергій Бондаренко — Тестування Drupal сайтiв з допогою TqExtension
 
Вадим Абрамчук — Big Drupal: Issues We Met
Вадим Абрамчук — Big Drupal: Issues We MetВадим Абрамчук — Big Drupal: Issues We Met
Вадим Абрамчук — Big Drupal: Issues We Met
 
Юрій Герасимов — Delayed operations with queues
Юрій Герасимов — Delayed operations with queuesЮрій Герасимов — Delayed operations with queues
Юрій Герасимов — Delayed operations with queues
 
Віталій Бобров — Web components, Polymer and Drupal
Віталій Бобров — Web components, Polymer and DrupalВіталій Бобров — Web components, Polymer and Drupal
Віталій Бобров — Web components, Polymer and Drupal
 
Олександр Щедров та Альбіна Тюпа — Magic button. Can production releases be s...
Олександр Щедров та Альбіна Тюпа — Magic button. Can production releases be s...Олександр Щедров та Альбіна Тюпа — Magic button. Can production releases be s...
Олександр Щедров та Альбіна Тюпа — Magic button. Can production releases be s...
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageControllerInterface

  • 3. Story 1 Save 1 000 000 nodes in 1 second
  • 4. XHProf ~ 4 seconds for 50 nodes. ~ 50% of the database time. ~ 100% of the fields update time.
  • 5. Anatomy of the node_save() field_attach_presave('node', $node); module_invoke_all('node_presave', $node); module_invoke_all('entity_presave', $node, 'node'); drupal_write_record('node', $node); You need all this if you want own fieldable entity. Procedural code is simple, isn’t it? _node_save_revision($node, $user->uid); node_invoke($node, $op); // $op == ‘update’ || $op == ‘insert’ ------------------------------------------------------------------------------------------- // Save fields.$function = "field_attach_$op";$function('node', $node); // field_attatch_update || field_attach_insert module_invoke($storage_info['module'], 'field_storage_write', …..); field_sql_storage_field_storage_write() Long time ago in a galaxy far away... ------------------------------------------------------------------------------------------- module_invoke_all('node_' . $op, $node);module_invoke_all('entity_' . $op, $node, 'node'); node_access_acquire_grants($node, $delete); entity_get_controller('node')->resetCache(array($node->nid));
  • 6. Field data field & field data revision
  • 7. foreach ($field['columns'] as $column => $attributes) { $columns[] = _field_sql_storage_columnname ($field_name, $column); } $query = db_insert($table_name)->fields($columns); $revision_query = db_insert($revision_name)->fields($columns); foreach ($field_languages as $langcode) { $items = (array) $entity->{$field_name}[$langcode]; $delta_count = 0; foreach ($items as $delta => $item) { // We now know we have someting to insert. $do_insert = TRUE; $record = array( Function loops for all fields in the entity end performs Delete/Insert 'entity_type' => $entity_type, 'entity_id' => $id, 'revision_id' => $vid, 'bundle' => $bundle, 'delta' => $delta, 'language' => $langcode, ); foreach ($field['columns'] as $column => $attributes) { $record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL; } $query->values($record); if (isset($vid)) { $revision_query->values($record); } if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) { break; } } } // Execute the query if we have values to insert. $query->execute(); $revision_query->execute(); } } if ($do_insert) {
  • 8. Can I haz some SQLs?
  • 9. Story 2 Back in my day...
  • 12. Why, Dries, why? https://drupal.org/node/1035804#comment-6860324 “This option is the one that "makes sense" to non-Drupal coders who have written some PHP by hand before now and think they know their way around making their own database schema. It's not wrong if you are building one thing once.. Nowadays however, if you choose to use the Drupal framework and build reusable tools, • • • All Drupal text entity fields must be translatable (non-negotiable) All Drupal entity fields must be revisionable (non-negotiable) All Drupal entity fields must support being multiple (negotiable, but it's easier to allow them to be multiple as it's free to do so) If the problem *you* are solving today doesn't actually seem to need all those features right now, that's quite likely. You may also know that you'll never need to do translations, and that a number of your values aren't going to need to be multiple (according to todays business rules anyway). Next year you'll probably wish you'd supported revisions, but that's next year.” © dman
  • 13. «I don’t need this» • Field SQL Norevisions: https://drupal.org/project/field_sql_norevisions • MongoDB: https://drupal.org/project/mongodb • Per-Bundle Storage: https://drupal.org/project/pbs • EntityFieldQuery Views Backend: https://drupal.org/project/efq_views • Own storage?
  • 14. Imagine 1. Storage level caching 2. Multi-update: node_save_multiple 3. Check if field was changed before performing a query 4. Simple storage without delta and language columns. 5. What else?
  • 15. I’ll write own storage with a…. 1. hook_field_storage_info(). 2. hook_field_storage_details(). 3. hook_field_storage_create_field(). 4. hook_field_storage_update_field(). 5. hook_field_storage_delete_field(). 6. hook_field_storage_load(). 7. hook_field_storage_write(). 8. hook_entity_query_alter(). 9. hook_field_storage_query(). 10. hook_field_attach_rename_bundle(). 11. hook_entity_insert(). 12. hook_entity_update(). 13. hook_field_attach_delete().
  • 16. Let’s do it quick http://posulliv.github.io/2013/01/07/bench-field-storage/ innodb_flush_log_at_trx_commit=0 innodb_doublewrite=0 log-bin=0 innodb_support_xa=0 innodb_buffer_pool_size=6G innodb_log_file_size=512M
  • 17. Curiosity is a way forward Drupal 8
  • 18.
  • 20. extends DatabaseStorageControllerNG which extends DatabaseStorageController which extends FieldableEntityStorageControllerBase which implements FieldableEntityStorageControllerInterface
  • 23. https://drupal.org/node/2068325 [META] Convert entity SQL queries to the Entity Query API