SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
POSTGRESQL & ROR

Tuesday, January 15, 13
SPEED   ...




Tuesday, January 15, 13
SPEED (OR LACK OF)




Tuesday, January 15, 13
SPEED (OR LACK OF)



                          90
         seconds
        for a page
Tuesday, January 15, 13
#1 LOCATION



                          112 000
                           locations




Tuesday, January 15, 13
#1 LOCATION




Tuesday, January 15, 13
select    row_to_json             (location)
                            from
                              (select id, ancestry, name, coordinates from locations)
                               as location
              {"id":23727,"ancestry":"214/217/22888","name":"Olho d'Água do Piauí","coordinates":"POINT (-42.53937 -5.84854)"}
              {"id":69289,"ancestry":"74/115/68153","name":"la Sentiu de Sió","coordinates":"POINT (0.86948 41.79807)"}




Tuesday, January 15, 13
select  array_to_json                (array_agg(location))
                             from
                               (select id, ancestry, name, coordinates from locations)
                                as location
                    [{"id":23727,"ancestry":"214/217/22888","name":"Olho d'Água do Piauí",
                    "coordinates":"POINT (-42.53937 -5.84854)"}, {"id"69289,"ancestry":"74/115/68153",
                    "name":"la Sentiu de Sió","coordinates":"POINT (0.86948 41.79807)"}]




Tuesday, January 15, 13
Tuesday, January 15, 13
Location.where('ancestry_depth < 3').
                                 select('id, ancestry, name, coordinates').all.
                                 inject({}) do |memo, record|
                                  memo[record.ancestry] << record
                                  memo
                                 end

                          { nil => [ <Location name=‘Europe’, id: 5 ...>, ... ],
                            “5” => [ <Location name=‘Poland’, id: 245>, ...],
                            ... }




Tuesday, January 15, 13
nodes[nil].collect { |location| prepare_node(location) }

            def prepare_node(location)
             node(location).
               merge(prepare_children(nodes[node_key_for_children(location)]))
            end

            def node(location)
             location.to_node_data
            end

            def prepare_children(children)
             { children: children.collect do |location|
                prepare_node(location)
               end
             }
            end

Tuesday, January 15, 13
to_json


Tuesday, January 15, 13
Oj.dump
                          to_json

Tuesday, January 15, 13
to_json   Oj      PostgreSQL


                   3000



                   2250



                   1500



                      750



                          0
                                         2314




Tuesday, January 15, 13
#1 LOCATION




Tuesday, January 15, 13
query: China

                          => <Location id: 9, name: “China”,
                               ancestry: “1” ... >
                          => ...
                          => <Location id: 26727, name: “Chinavita”,
                               ancestry: “214/228/26242” ... >




Tuesday, January 15, 13
query: China

                          => <Location id:    9, name: “China”,
                                   ancestry: “1” ... >
                          => ...
                          => <Location id:    26727, name: “Chinavita”,
                                   ancestry: “214/228/26242” ... >




Tuesday, January 15, 13
CREATE OR REPLACE FUNCTION find_locations_with_ancestors(text, boolean)
               RETURNS int[] AS
              $$
              DECLARE
               search_result_ids int[];
               all_ids int[];
               pattern text;
              BEGIN
               pattern := '^('||$1||')|[ |,]('||$1||')';
               FOR search_result_ids IN (
                      select (locations.id || string_to_array(locations.ancestry, '/')::int[]) as ids
                         from locations
                      where
                         (locations.name ~* pattern or locations.code ~* pattern or locations.alternative_name ~* pattern)
                         and (not($2) or locations.coordinates = ''
                         or locations.coordinates is null)
                   ) LOOP
                 all_ids := all_ids || search_result_ids;
               END LOOP;
               RETURN all_ids;
              END;
              $$
              LANGUAGE plpgsql;

Tuesday, January 15, 13
scope :find_with_ancestors, ->(query, only_without_coordinates) do
                       where('array[locations.id] <@
                         (select * from find_locations_with_ancestors(?, ?))',
                         query, only_without_coordinates)
                      end




Tuesday, January 15, 13
find_locations_with_ancestors = (quary::text, without_cordinates::boolean) ->
                           declare:
                             record_location_ids::int[]
                             ids::int[]
                            begin:

                             FOR record_location_ids IN
                               :ruby-
                                 pattern = /^('||$1||')|[ |,]('||$1||')/
                               :ruby=
                                 Location.where{
                                   { name: pattern, code: pattern, alternative_name: pattern }.sql_or,
                                   ‘(not($2) or locations.coordinates = '' or locations.coordinates is null)’
                                 }.select{
                                   id || string_to_array(ancestry, ‘/’)::int[]) as ids
                                 }.to_sql
                               ) LOOP
                                  all_ids := all_ids || search_result_ids
                              END LOOP
                             RETURN all_ids




Tuesday, January 15, 13
Tuesday, January 15, 13
RAILS 4 :-)


                                  hstore

                                  array (int, string)

                                  ranges (date, time, int) [?]




Tuesday, January 15, 13
Tuesday, January 15, 13
PICTURES SOURCE


                 http://xanthe93.deviantart.com/art/Steampunk-Elephant-Train-
                 Lineart-290163415

                 http://www.businessinsider.com/fastest-trains-in-the-world-2011-11?op=1

                 http://www.fortogden.com/goldenspike.html

                 http://noweevil.com/portfolio/wednesday-morning-wakeup-call-20-photos/

                 http://www.softicons.com/free-icons/application-icons/ruby-programming-
                 icons-by-ahmad-galal/ruby-on-rails-icon




Tuesday, January 15, 13

Contenu connexe

Tendances

Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
PHP Static Code Review
PHP Static Code ReviewPHP Static Code Review
PHP Static Code ReviewDamien Seguy
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency InjectionRifat Nabi
 
Using Templates to Achieve Awesomer Architecture
Using Templates to Achieve Awesomer ArchitectureUsing Templates to Achieve Awesomer Architecture
Using Templates to Achieve Awesomer ArchitectureGarann Means
 
Drush. Secrets come out.
Drush. Secrets come out.Drush. Secrets come out.
Drush. Secrets come out.Alex S
 
Command-Oriented Architecture
Command-Oriented ArchitectureCommand-Oriented Architecture
Command-Oriented ArchitectureLuiz Messias
 
앱스프레소를 이용한 모바일 앱 개발(2)
앱스프레소를 이용한 모바일 앱 개발(2)앱스프레소를 이용한 모바일 앱 개발(2)
앱스프레소를 이용한 모바일 앱 개발(2)mosaicnet
 
Implementation Specifications
Implementation SpecificationsImplementation Specifications
Implementation SpecificationsUnmon Mukherjee
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressionsplarsen67
 
Drupal csu-open atriumname
Drupal csu-open atriumnameDrupal csu-open atriumname
Drupal csu-open atriumnameEmanuele Quinto
 

Tendances (20)

Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
PHP Static Code Review
PHP Static Code ReviewPHP Static Code Review
PHP Static Code Review
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Lenses
LensesLenses
Lenses
 
Using Templates to Achieve Awesomer Architecture
Using Templates to Achieve Awesomer ArchitectureUsing Templates to Achieve Awesomer Architecture
Using Templates to Achieve Awesomer Architecture
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
 
Drush. Secrets come out.
Drush. Secrets come out.Drush. Secrets come out.
Drush. Secrets come out.
 
Command-Oriented Architecture
Command-Oriented ArchitectureCommand-Oriented Architecture
Command-Oriented Architecture
 
앱스프레소를 이용한 모바일 앱 개발(2)
앱스프레소를 이용한 모바일 앱 개발(2)앱스프레소를 이용한 모바일 앱 개발(2)
앱스프레소를 이용한 모바일 앱 개발(2)
 
Ricky Bobby's World
Ricky Bobby's WorldRicky Bobby's World
Ricky Bobby's World
 
CakeFest 2013 keynote
CakeFest 2013 keynoteCakeFest 2013 keynote
CakeFest 2013 keynote
 
Implementation Specifications
Implementation SpecificationsImplementation Specifications
Implementation Specifications
 
Presentation1
Presentation1Presentation1
Presentation1
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressions
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
 
Drupal csu-open atriumname
Drupal csu-open atriumnameDrupal csu-open atriumname
Drupal csu-open atriumname
 
Coding website
Coding websiteCoding website
Coding website
 

En vedette

Unittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleUnittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleBenjamin Eberlei
 
User Testing by Example
User Testing by ExampleUser Testing by Example
User Testing by ExampleJeremy Horn
 
Bad test, good test
Bad test, good testBad test, good test
Bad test, good testSeb Rose
 
Specification by Example
Specification by ExampleSpecification by Example
Specification by ExampleSergey Shishkin
 
Unit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleUnit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleBenjamin Eberlei
 
Specifications For Enterprise Testing
Specifications For Enterprise TestingSpecifications For Enterprise Testing
Specifications For Enterprise TestingSathyan Sethumadhavan
 
7 1-1 soap-developers_guide
7 1-1 soap-developers_guide7 1-1 soap-developers_guide
7 1-1 soap-developers_guideNugroho Hermanto
 
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Tom Eston
 
Moving Towards Zero Defects with Specification by Example
Moving Towards Zero Defects with Specification by ExampleMoving Towards Zero Defects with Specification by Example
Moving Towards Zero Defects with Specification by ExampleSteve Rogalsky
 
Types of Software Testing
Types of Software TestingTypes of Software Testing
Types of Software TestingNishant Worah
 
Testing concepts ppt
Testing concepts pptTesting concepts ppt
Testing concepts pptRathna Priya
 
Introduction to Agile software testing
Introduction to Agile software testingIntroduction to Agile software testing
Introduction to Agile software testingKMS Technology
 
Agile Testing Process
Agile Testing ProcessAgile Testing Process
Agile Testing ProcessIntetics
 
Software Testing Fundamentals
Software Testing FundamentalsSoftware Testing Fundamentals
Software Testing FundamentalsChankey Pathak
 

En vedette (20)

Unittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleUnittesting Bad-Practices by Example
Unittesting Bad-Practices by Example
 
User Testing by Example
User Testing by ExampleUser Testing by Example
User Testing by Example
 
Domino testing presentation
Domino testing presentationDomino testing presentation
Domino testing presentation
 
Bad test, good test
Bad test, good testBad test, good test
Bad test, good test
 
Specification by Example
Specification by ExampleSpecification by Example
Specification by Example
 
Unit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleUnit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by Example
 
Testing
TestingTesting
Testing
 
Specifications For Enterprise Testing
Specifications For Enterprise TestingSpecifications For Enterprise Testing
Specifications For Enterprise Testing
 
7 1-1 soap-developers_guide
7 1-1 soap-developers_guide7 1-1 soap-developers_guide
7 1-1 soap-developers_guide
 
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
 
Moving Towards Zero Defects with Specification by Example
Moving Towards Zero Defects with Specification by ExampleMoving Towards Zero Defects with Specification by Example
Moving Towards Zero Defects with Specification by Example
 
Learn SoapUI
Learn SoapUILearn SoapUI
Learn SoapUI
 
Agile Testing by Example
Agile Testing by ExampleAgile Testing by Example
Agile Testing by Example
 
Manual testing ppt
Manual testing pptManual testing ppt
Manual testing ppt
 
Types of Software Testing
Types of Software TestingTypes of Software Testing
Types of Software Testing
 
Testing concepts ppt
Testing concepts pptTesting concepts ppt
Testing concepts ppt
 
Introduction to Agile software testing
Introduction to Agile software testingIntroduction to Agile software testing
Introduction to Agile software testing
 
Agile Testing Process
Agile Testing ProcessAgile Testing Process
Agile Testing Process
 
Software Testing Fundamentals
Software Testing FundamentalsSoftware Testing Fundamentals
Software Testing Fundamentals
 
The Minimum Loveable Product
The Minimum Loveable ProductThe Minimum Loveable Product
The Minimum Loveable Product
 

Similaire à Postgresql and ror

Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrowPete McFarlane
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPaweł Dawczak
 
Parsing with Perl6 Grammars
Parsing with Perl6 GrammarsParsing with Perl6 Grammars
Parsing with Perl6 Grammarsabrummett
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...adrianoalmeida7
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubyJason Yeo Jie Shun
 
Beautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsBeautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsJesse Donat
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
Taking Inspiration From The Functional World
Taking Inspiration From The Functional WorldTaking Inspiration From The Functional World
Taking Inspiration From The Functional WorldPiotr Solnica
 

Similaire à Postgresql and ror (18)

CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
Parsing with Perl6 Grammars
Parsing with Perl6 GrammarsParsing with Perl6 Grammars
Parsing with Perl6 Grammars
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
 
C arrays
C arraysC arrays
C arrays
 
Programação Funcional
Programação FuncionalProgramação Funcional
Programação Funcional
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
 
Beautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsBeautiful PHP CLI Scripts
Beautiful PHP CLI Scripts
 
Fluent14
Fluent14Fluent14
Fluent14
 
Groovy
GroovyGroovy
Groovy
 
DBI
DBIDBI
DBI
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
Ns2programs
Ns2programsNs2programs
Ns2programs
 
Taking Inspiration From The Functional World
Taking Inspiration From The Functional WorldTaking Inspiration From The Functional World
Taking Inspiration From The Functional World
 

Dernier

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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 organizationRadu Cotescu
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Postgresql and ror

  • 1. POSTGRESQL & ROR Tuesday, January 15, 13
  • 2. SPEED ... Tuesday, January 15, 13
  • 3. SPEED (OR LACK OF) Tuesday, January 15, 13
  • 4. SPEED (OR LACK OF) 90 seconds for a page Tuesday, January 15, 13
  • 5. #1 LOCATION 112 000 locations Tuesday, January 15, 13
  • 7. select row_to_json (location) from (select id, ancestry, name, coordinates from locations) as location {"id":23727,"ancestry":"214/217/22888","name":"Olho d'Água do Piauí","coordinates":"POINT (-42.53937 -5.84854)"} {"id":69289,"ancestry":"74/115/68153","name":"la Sentiu de Sió","coordinates":"POINT (0.86948 41.79807)"} Tuesday, January 15, 13
  • 8. select array_to_json (array_agg(location)) from (select id, ancestry, name, coordinates from locations) as location [{"id":23727,"ancestry":"214/217/22888","name":"Olho d'Água do Piauí", "coordinates":"POINT (-42.53937 -5.84854)"}, {"id"69289,"ancestry":"74/115/68153", "name":"la Sentiu de Sió","coordinates":"POINT (0.86948 41.79807)"}] Tuesday, January 15, 13
  • 10. Location.where('ancestry_depth < 3'). select('id, ancestry, name, coordinates').all. inject({}) do |memo, record| memo[record.ancestry] << record memo end { nil => [ <Location name=‘Europe’, id: 5 ...>, ... ], “5” => [ <Location name=‘Poland’, id: 245>, ...], ... } Tuesday, January 15, 13
  • 11. nodes[nil].collect { |location| prepare_node(location) } def prepare_node(location) node(location). merge(prepare_children(nodes[node_key_for_children(location)])) end def node(location) location.to_node_data end def prepare_children(children) { children: children.collect do |location| prepare_node(location) end } end Tuesday, January 15, 13
  • 13. Oj.dump to_json Tuesday, January 15, 13
  • 14. to_json Oj PostgreSQL 3000 2250 1500 750 0 2314 Tuesday, January 15, 13
  • 16. query: China => <Location id: 9, name: “China”, ancestry: “1” ... > => ... => <Location id: 26727, name: “Chinavita”, ancestry: “214/228/26242” ... > Tuesday, January 15, 13
  • 17. query: China => <Location id: 9, name: “China”, ancestry: “1” ... > => ... => <Location id: 26727, name: “Chinavita”, ancestry: “214/228/26242” ... > Tuesday, January 15, 13
  • 18. CREATE OR REPLACE FUNCTION find_locations_with_ancestors(text, boolean) RETURNS int[] AS $$ DECLARE search_result_ids int[]; all_ids int[]; pattern text; BEGIN pattern := '^('||$1||')|[ |,]('||$1||')'; FOR search_result_ids IN ( select (locations.id || string_to_array(locations.ancestry, '/')::int[]) as ids from locations where (locations.name ~* pattern or locations.code ~* pattern or locations.alternative_name ~* pattern) and (not($2) or locations.coordinates = '' or locations.coordinates is null) ) LOOP all_ids := all_ids || search_result_ids; END LOOP; RETURN all_ids; END; $$ LANGUAGE plpgsql; Tuesday, January 15, 13
  • 19. scope :find_with_ancestors, ->(query, only_without_coordinates) do where('array[locations.id] <@ (select * from find_locations_with_ancestors(?, ?))', query, only_without_coordinates) end Tuesday, January 15, 13
  • 20. find_locations_with_ancestors = (quary::text, without_cordinates::boolean) -> declare: record_location_ids::int[] ids::int[] begin: FOR record_location_ids IN :ruby- pattern = /^('||$1||')|[ |,]('||$1||')/ :ruby= Location.where{ { name: pattern, code: pattern, alternative_name: pattern }.sql_or, ‘(not($2) or locations.coordinates = '' or locations.coordinates is null)’ }.select{ id || string_to_array(ancestry, ‘/’)::int[]) as ids }.to_sql ) LOOP all_ids := all_ids || search_result_ids END LOOP RETURN all_ids Tuesday, January 15, 13
  • 22. RAILS 4 :-) hstore array (int, string) ranges (date, time, int) [?] Tuesday, January 15, 13
  • 24. PICTURES SOURCE http://xanthe93.deviantart.com/art/Steampunk-Elephant-Train- Lineart-290163415 http://www.businessinsider.com/fastest-trains-in-the-world-2011-11?op=1 http://www.fortogden.com/goldenspike.html http://noweevil.com/portfolio/wednesday-morning-wakeup-call-20-photos/ http://www.softicons.com/free-icons/application-icons/ruby-programming- icons-by-ahmad-galal/ruby-on-rails-icon Tuesday, January 15, 13