N+1 query problem
- ORMs make it easy to a query per loop iteration, which we want to avoid
eager_load
- single query (left outer join)
- can reference the other table's columns in
where
preload
- a few queries (one per table)
- typically faster
N+1 query problem
eager_load
wherepreload
| class Node: | |
| def __init__(self, data): | |
| self.data = data | |
| self.next = None | |
| class LinkedList: | |
| def __init__(self): | |
| self.head = None | |
| def form_ll(self, length): |
To Launch an EC2 instance from aws console with all the credentials and configurations hooked.
| class PaytmController < ApplicationController | |
| skip_before_action :verify_authenticity_token | |
| def paytm | |
| @checksum = new_pg_checksum(params, MERCHANT_KEY) # MERCHANT_KEY = your Merchant key | |
| end | |
| def handle_payment | |
| if params["CHECKSUMHASH"] | |
| paytmHash = Hash.new |
| require 'contentful' | |
| client = Contentful::Client.new( | |
| space: '<spacd_id>', | |
| access_token: '<access-token>', | |
| dynamic_entries: :auto | |
| ) | |
| entries = client.entries # For grabbing entries | |
| entries.each do |entry| |
| queue<TreeNode*> q; // To store the node addresses | |
| vector<int> result; // To store the values in the node | |
| result.push_back(root->val); | |
| q.push(root); | |
| while (!q.empty()) { | |
| node = q.front(); | |
| q.pop(); | |
| if(node->left){ | |
| result.push_back(node->left->val); | |
| q.push(node->left); |
| #include <iostream> | |
| using namespace std; | |
| struct Node{ | |
| int data; | |
| struct Node *next; | |
| }; | |
| int hash_(int key) | |
| { |
| #include <iostream> | |
| using namespace std; | |
| struct Node{ | |
| int data; | |
| struct Node *next; | |
| }; | |
| int main(){ |
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| vector <int> a = {0}; | |
| void insert(int ele){ | |
| int temp; | |
| a.push_back(ele); | |
| long last = a.size()-1; |
| =begin | |
| 687.to_s(2) # "1010101111" | |
| "1010101111".to_i(2) # 687 | |
| =end | |
| def find_complement(num) | |
| num = num.to_s(2).chars | |
| num.map!{|i| i.to_i} | |
| for x in 0..num.size-1 do | |
| if num[x]==0 |