]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1543489 - Update firefox-crash-table.js to use cached firefox_versions.json
authorKohei Yoshino <kohei.yoshino@gmail.com>
Tue, 28 May 2019 18:51:11 +0000 (14:51 -0400)
committerGitHub <noreply@github.com>
Tue, 28 May 2019 18:51:11 +0000 (14:51 -0400)
extensions/BMO/Extension.pm
extensions/BMO/template/en/default/hook/bug_modal/edit-after_modules.html.tmpl
extensions/BMO/web/js/firefox-crash-table.js

index f1e98c1cdd537ec2098e90b1f8c08628d7a409ac..50dba3d70e60def8487f81330351629464cf50be 100644 (file)
@@ -174,6 +174,7 @@ sub template_before_process {
     }
   }
   elsif ($file eq 'bug/edit.html.tmpl' || $file eq 'bug_modal/edit.html.tmpl') {
+    $vars->{firefox_versions} = _fetch_product_version_file('firefox', 1);
     $vars->{split_cf_crash_signature} = $self->_split_crash_signature($vars);
   }
 
@@ -2664,12 +2665,14 @@ sub enter_bug_entrydefaultvars {
   }
 }
 
-sub _get_product_version {
-  my ($product, $channel, $detail) = @_;
+sub _fetch_product_version_file {
+  my ($product, $cache_only) = @_;
   my $key      = "${product}_versions";
   my $versions = Bugzilla->request_cache->{$key}
     || Bugzilla->memcached->get_data({key => $key});
 
+  return $versions if $cache_only;
+
   unless ($versions) {
     my $ua = Mojo::UserAgent->new;
     if (my $proxy_url = Bugzilla->params->{'proxy_url'}) {
@@ -2687,6 +2690,12 @@ sub _get_product_version {
     });
   }
 
+  return $versions;
+}
+
+sub _get_product_version {
+  my ($product, $channel, $detail) = @_;
+  my $versions = _fetch_product_version_file($product);
   my $version = $versions->{PRODUCT_CHANNELS->{$product}->{$channel}->{json_key}};
   return $version if $detail;
 
index 0723eba01c13d2c62ced49bc5fa8ed960e350485..7b9cceaa35b35e08d5234d198784f12b1f5f4bd0 100644 (file)
@@ -7,3 +7,7 @@
   #%]
 
 [% INCLUDE bug/legal_disclaimer.html.tmpl %]
+
+[% IF firefox_versions %]
+  <meta name="firefox-versions" content="[% json_encode(firefox_versions) FILTER html %]">
+[% END %]
index 5cc164c02db0a4b9f1012505eb51b8bbc441d8fc..26919dbf182eb563cf27cfcbca0d4c013a753230 100644 (file)
@@ -12,6 +12,12 @@ window.addEventListener('DOMContentLoaded', () => {
   const VERSION = "0.4.0";
 
   async function fetchProductDetails() {
+    const $meta = document.querySelector('meta[name="firefox-versions"]');
+
+    if ($meta) {
+      return JSON.parse($meta.content);
+    }
+
     const url = "https://product-details.mozilla.org/1.0/firefox_versions.json";
     const response = await fetch(url);
     return await response.json();