Skip to content

Instantly share code, notes, and snippets.

@malomalo
Last active November 15, 2017 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malomalo/6dc5a2e036f7f94d188aafe4244c84ad to your computer and use it in GitHub Desktop.
Save malomalo/6dc5a2e036f7f94d188aafe4244c84ad to your computer and use it in GitHub Desktop.
require 'jbuilder'
require 'jbuilder/jbuilder_template'
module Rails
def self.cache
@cache ||= ActiveSupport::Cache::MemoryStore.new
end
end
# Fill the cache
JbuilderTemplate.encode FakeContext.new do |json|
json.cached do
json.cache! 'jbcached' do
json.array! 0..100 do |i|
json.a i
json.b i
json.c i
json.d i
json.e i
json.subitems 0..100 do |j|
json.f i.to_s * j
json.g i.to_s * j
json.h i.to_s * j
json.i i.to_s * j
json.j i.to_s * j
end
end
end
end
end
# Everthing before this is run once initialy, after is the test
__SETUP__
JbuilderTemplate.encode FakeContext.new do |json|
json.cached do
json.cache! 'jbcached' do
json.array! 0..100 do |i|
json.a i
json.b i
json.c i
json.d i
json.e i
json.subitems 0..100 do |j|
json.f i.to_s * j
json.g i.to_s * j
json.h i.to_s * j
json.i i.to_s * j
json.j i.to_s * j
end
end
end
end
end
# This is file is prepended to the test so it's run once before any
# of the test code
require "active_support"
require 'action_view'
require 'action_view/testing/resolvers'
class FakeController
def perform_caching
true
end
def instrument_fragment_cache(a, b)
yield
end
end
class FakeContext
attr_reader :controller
def initialize
@controller = FakeController.new
end
end
gem install 'analyzer'
analyze jbuilder.rb turbostream.rb -l lib.rb
require 'turbostreamer'
require 'turbostreamer/handler'
require 'turbostreamer/template'
module Rails
def self.cache
@cache ||= ActiveSupport::Cache::MemoryStore.new
end
end
# Fill the cache
TurboStreamer::Template.encode FakeContext.new do |json|
json.object! do
json.cached do
json.cache! 'tscached' do
json.array! 0..100 do |i|
json.object! do
json.a i
json.b i
json.c i
json.d i
json.e i
json.subitems 0..100 do |j|
json.object! do
json.f i.to_s * j
json.g i.to_s * j
json.h i.to_s * j
json.i i.to_s * j
json.j i.to_s * j
end
end
end
end
end
end
end
end
# Everthing before this is run once initialy, after is the test
__SETUP__
TurboStreamer::Template.encode FakeContext.new do |json|
json.object! do
json.cached do
json.cache! 'tscached' do
json.array! 0..100 do |i|
json.object! do
json.a i
json.b i
json.c i
json.d i
json.e i
json.subitems 0..100 do |j|
json.object! do
json.f i.to_s * j
json.g i.to_s * j
json.h i.to_s * j
json.i i.to_s * j
json.j i.to_s * j
end
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment