From 3f049da0a08de64dadf036d585df2fa5f61993d2 Mon Sep 17 00:00:00 2001 From: Alexander Meindl Date: Wed, 4 Jan 2023 17:11:45 +0100 Subject: [PATCH] show caching information for async dashboard block --- app/helpers/dashboards_helper.rb | 8 ++++++++ app/models/dashboard_content.rb | 22 ++++++++++++++++++++++ config/locales/cs.yml | 1 + config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fr.yml | 1 + config/locales/it.yml | 1 + config/locales/ja.yml | 1 + config/locales/ko.yml | 1 + config/locales/pl.yml | 1 + config/locales/pt-BR.yml | 1 + config/locales/ru.yml | 1 + config/locales/zh-TW.yml | 1 + config/locales/zh.yml | 1 + 15 files changed, 43 insertions(+) diff --git a/app/helpers/dashboards_helper.rb b/app/helpers/dashboards_helper.rb index d2cf89a6..9de9fef6 100644 --- a/app/helpers/dashboards_helper.rb +++ b/app/helpers/dashboards_helper.rb @@ -223,6 +223,9 @@ module DashboardsHelper class: 'icon-only icon-settings', title: l(:label_options)) end + if block_definition.key? :async + icons << tag.span('', class: 'icon-only icon-warning', title: dashboard_block_sync_info(block_definition)) + end icons << tag.span('', class: 'icon-only icon-sort-handle sort-handle', title: l(:button_move)) icons << delete_link(_remove_block_dashboard_path(@project, dashboard, block: block), method: :post, @@ -430,6 +433,11 @@ module DashboardsHelper private + def dashboard_block_sync_info(block_definition) + sec = block_definition[:async][:cache_expires_in].presence || DashboardContent::RENDER_ASYNC_CACHE_EXPIRES_IN + l :dashboard_block_info_async, seconds: sec + end + # Renders a single block content def render_dashboard_block_content(block, block_definition, dashboard, **overwritten_settings) settings = dashboard.layout_settings block diff --git a/app/models/dashboard_content.rb b/app/models/dashboard_content.rb index 8b54b692..173bf1fb 100644 --- a/app/models/dashboard_content.rb +++ b/app/models/dashboard_content.rb @@ -118,6 +118,28 @@ class DashboardContent private + def issues_cache_expires_in + issue_count = Rails.cache.fetch project.issues.visible.count, expires_in: 1.hour do + if project + project.issues.visible.count + else + Issue.visible.count + end + end + + if issue_count > 10_000 + 86_400 # 1 day + elsif issue_count > 1_000 + 3_600 # 1 hour + else + 60 + end + end + + def issues_cache_key + Digest::SHA256.hexdigest [project&.id, User.current.id].compact.join('-') + end + # if more the one permission is specified, all permissions are required def block_permission_allowed?(permission) Array(permission).all? { |p| user.allowed_to?(p, project, global: true) } diff --git a/config/locales/cs.yml b/config/locales/cs.yml index d9d578c5..198ad7d2 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -197,3 +197,4 @@ cs: label_all_projects: "Všechny projekty" notice_failed_to_save_entries: "%{count} z %{total} vybrané %{name_plural} nelze uložit: %{ids}." field_notes_count: "Počet komentářů" + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/de.yml b/config/locales/de.yml index 793a2547..74c24ac4 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -197,3 +197,4 @@ de: label_all_projects: Alle Projekte notice_failed_to_save_entries: "%{count} von %{total} ausgewählten %{name_plural} konnte(n) nicht gespeichert werden: %{ids}." field_notes_count: Anzahl Kommentare + dashboard_block_info_async: Dieser Block wird asynchron geladen und %{seconds} Sekunden gecached. diff --git a/config/locales/en.yml b/config/locales/en.yml index b3bba0fc..41b9ae84 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -197,3 +197,4 @@ en: label_all_projects: All projects notice_failed_to_save_entries: "%{count} of %{total} selected %{name_plural} could not be saved : %{ids}." field_notes_count: Notes amount + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/es.yml b/config/locales/es.yml index 106aaae2..77b6fcaa 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -197,3 +197,4 @@ es: label_all_projects: Todos los proyectos notice_failed_to_save_entries: "%{count} de %{total} %{name_plural} seleccionados no pudieron ser salvados: %{ids}." field_notes_count: "Número de comentarios" + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/fr.yml b/config/locales/fr.yml index decee7f9..ae5030dd 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -197,3 +197,4 @@ fr: label_all_projects: Tous les projets notice_failed_to_save_entries: "%{count} des %{total} %{name_plural} sélectionnés n'ont pu être sauvegardés: %{ids}." field_notes_count: Total des commentaires + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/it.yml b/config/locales/it.yml index 4a5f923c..84305c74 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -197,3 +197,4 @@ it: label_all_projects: Tutti i progetti notice_failed_to_save_entries: "Non è stato possibile salvare %{count} dei %{total} %{name_plural} selezionati: %{ids}." field_notes_count: Totale dei commenti + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 9cf09b91..6c200394 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -197,3 +197,4 @@ ja: label_all_projects: すべてのプロジェクト notice_failed_to_save_entries: "%{count} of %{total} selected %{name_plural} could not be saved: %{ids}." field_notes_count: コメント数 + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 7e2ccab4..b5eed036 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -197,3 +197,4 @@ ko: label_all_projects: 모든 프로젝트 notice_failed_to_save_entries: "%{count} of %{total} selected %{name_plural} could not be saved: %{ids}." field_notes_count: 메모의 수 + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 39991931..335d9008 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -197,3 +197,4 @@ pl: label_all_projects: Wszystkie projekty notice_failed_to_save_entries: "%{count} z %{total} wybranych %{name_plural} nie mogły zostać zapisane: %{ids}." field_notes_count: Liczba uwag + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index a9467aff..b4995e7f 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -197,3 +197,4 @@ pt-BR: label_all_projects: Todos os Projekte notice_failed_to_save_entries: "%{count} de %{total} %{name_plural} selecionados não puderam ser salvos: %{ids}." field_notes_count: "Volume de comentários" + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 810728d6..252969c7 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -197,3 +197,4 @@ ru: label_all_projects: Все проекты notice_failed_to_save_entries: "%{count} из %{total} выбранных %{name_plural} не удалось сохранить: %{ids}." field_notes_count: Количество комментариев + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index d604ed84..a98618b0 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -197,3 +197,4 @@ label_all_projects: 所有项目 notice_failed_to_save_entries: "%{count} of %{total} selected %{name_plural} could not be saved : %{ids}." field_notes_count: 评论的数量 + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds. diff --git a/config/locales/zh.yml b/config/locales/zh.yml index fbe64958..8e269a3f 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -197,3 +197,4 @@ zh: label_all_projects: 所有项目 notice_failed_to_save_entries: "%{count} of %{total} selected %{name_plural} could not be saved : %{ids}." field_notes_count: 评论的数量 + dashboard_block_info_async: This block is loaded asynchronous and cached for %{seconds} seconds.