diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-03-30 19:29:17 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-03-30 19:29:17 +0200 |
commit | 5830d80b8d2b87daa9123dc248ae00e2ed90069c (patch) | |
tree | 3c425ef514f03cc2b2b1107c6c53dbf5d8667b60 /lib/tasks | |
parent | 8718acdf80f5dcc70fdd625dfb0d073924132628 (diff) | |
download | gitlab-ce-5830d80b8d2b87daa9123dc248ae00e2ed90069c.tar.gz |
Pre-calculate Emoji digestsprecompile-emoji-urls
By pre-calculating the digests we can manually construct the emoji URLs,
removing the need for using Rails' asset URL helpers. The reason we
don't want to use these helpers for Emojis is two-fold:
1. Rails' image_url() method is slow, really slow. For one it _might_
have to calculate digests but it also performs a lot of other
intensive operations (judging by the source code and based on
measuring timings).
2. We have a lot of Emoji which coupled with the above can result in it
taking minutes to load Emoji autocomplete data.
Using this pre-calculation setup generating the digests takes around 7
seconds (including the time it takes to start Rails/Rake), and only
around 600 milliseconds to load _all_ the autocomplete data of a project
(measured locally).
This commit _does_ change the Emoji URLs from absolute to relative URLs
as these are much easier to generate.
To update the Emoji data simply run:
rake gemojione:digests
Then commit any changes.
Fixes gitlab-org/gitlab-ce#14009
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gemojione.rake | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/lib/tasks/gemojione.rake b/lib/tasks/gemojione.rake index cfaf4a129b1..7ec00a898fd 100644 --- a/lib/tasks/gemojione.rake +++ b/lib/tasks/gemojione.rake @@ -1,19 +1,39 @@ -# This task will generate a standard and Retina sprite of all of the current -# Gemojione Emojis, with the accompanying SCSS map. -# -# It will not appear in `rake -T` output, and the dependent gems are not -# included in the Gemfile by default, because this task will only be needed -# occasionally, such as when new Emojis are added to Gemojione. - -begin - require 'sprite_factory' - require 'rmagick' -rescue LoadError - # noop -end - namespace :gemojione do + desc 'Generates Emoji SHA256 digests' + task digests: :environment do + require 'digest/sha2' + require 'json' + + dir = Gemojione.index.images_path + + digests = AwardEmoji.emojis.map do |name, emoji_hash| + fpath = File.join(dir, "#{emoji_hash['unicode']}.png") + digest = Digest::SHA256.file(fpath).hexdigest + + { name: name, unicode: emoji_hash['unicode'], digest: digest } + end + + out = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json') + + File.open(out, 'w') do |handle| + handle.write(JSON.pretty_generate(digests)) + end + end + + # This task will generate a standard and Retina sprite of all of the current + # Gemojione Emojis, with the accompanying SCSS map. + # + # It will not appear in `rake -T` output, and the dependent gems are not + # included in the Gemfile by default, because this task will only be needed + # occasionally, such as when new Emojis are added to Gemojione. task sprite: :environment do + begin + require 'sprite_factory' + require 'rmagick' + rescue LoadError + # noop + end + check_requirements! SIZE = 20 |