Skip to content

Instantly share code, notes, and snippets.

@karreiro
Last active May 12, 2022 07:57
Show Gist options
  • Select an option

  • Save karreiro/f613bda66fc334337135f7df48f09129 to your computer and use it in GitHub Desktop.

Select an option

Save karreiro/f613bda66fc334337135f7df48f09129 to your computer and use it in GitHub Desktop.
require "httparty"
require "benchmark"
# ==============================================================================
YOUR_STORE_URL = "https://shop1.shopify.bulk7.guilherme-carreiro.eu.spin.dev"
YOUR_CUSTOM_APP_PASSWORD = "shpat_11111111111111111"
# ==============================================================================
REF_SIZE = 1_048_576 / 5
def random_string
(0...4).map { (65 + rand(26)).chr }.join
end
def update_asset(url, body)
HTTParty.put(url,
body: body.to_json,
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer #{YOUR_CUSTOM_APP_PASSWORD}",
"X-Shopify-Access-Token": YOUR_CUSTOM_APP_PASSWORD
}
)
end
bulk_req = Benchmark.measure do
assets = 10.times.map do |i|
text = random_string * (REF_SIZE/10)
{
"key" => "assets\/file#{i}.txt",
"value" => text
}
end
update_asset("#{YOUR_STORE_URL}/admin/api/unstable/themes/1/assets/bulk.json", {
"assets" => assets
})
end
puts "bulk_req => #{bulk_req.real}"
multiple_reqs = Benchmark.measure do
10.times do |i|
text = random_string * (REF_SIZE/10)
update_asset("#{YOUR_STORE_URL}/admin/api/unstable/themes/1/assets.json", {
"asset" => {
"key" => "assets\/file#{i}.txt",
"value" => text
}
})
end
end
puts "multiple_reqs => #{multiple_reqs.real}"
# bulk_req => 3.7107140000443906
# multiple_reqs => 13.339985999977216
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment