This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m max_size=10g | |
| inactive=60m use_temp_path=off; | |
| server { | |
| ... | |
| location / { | |
| proxy_cache my_cache; | |
| proxy_cache_revalidate on; | |
| proxy_cache_min_uses 1; | |
| proxy_cache_use_stale error timeout updating http_500 http_502 http_503 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Product <ActiveRecord::Base | |
| after_commit :prerender | |
| def prerender | |
| keys = [ [:user, :admin, :moderator, nil], [:ru, :en ] ] | |
| keys.pop.product(*keys).each do |lr| | |
| # lr - locale + role | |
| ApplicationController.render( | |
| assigns: {locals: {product: self, role: lr[1], locale: lr[0]} }, | |
| inline: '<% render partial: "products/product", locals: @locals %>') | |
| #of course products/_product.html.slim must start with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # nil means current_user is empty i.e. it's a guest | |
| keys = [ [:user, :admin, :moderator, nil], [:ru, :en ] ] | |
| # all combination of keys: | |
| all_flatten_keys = keys.pop.product(*keys) | |
| # [[:ru, :user], [:ru, :admin], [:ru, :moderator], [:ru, nil], | |
| # [:en, :user], [:en, :admin], [:en, :moderator], [:en, nil]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DB way | |
| Shipment.scope | |
| .joins(purchase: :product) | |
| .select(["shipments.*","sum(purchases.items_count*products.gross_weight) as gross_weight"]) | |
| .group("shipments.id") |
NewerOlder