aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorMax Magorsch <max@magorsch.de>2019-10-07 15:19:47 +0200
committerMax Magorsch <max@magorsch.de>2019-10-07 15:19:47 +0200
commite3c15ed4cc0fbfa165103b57e69859be32a9cd0e (patch)
treeebd404dcfe6daee95bcddb7404b186b391d20f85 /app
parentMerge tag 'v7.0.2' into dev/es-7.3 (diff)
downloadpackages-5-e3c15ed4cc0fbfa165103b57e69859be32a9cd0e.tar.gz
packages-5-e3c15ed4cc0fbfa165103b57e69859be32a9cd0e.tar.bz2
packages-5-e3c15ed4cc0fbfa165103b57e69859be32a9cd0e.zip
Remove dynamic field names from the packages index
So far, dynamic field names have been used for useflags in the packages index. This leads to a large number of fields, which is continuously growing, as obsolete fields are not cleaned up from the mapping when the useflag is deleted. This way, the maximum limit of 50000 fields may be hit. To avoid this, the dynamic field names have been removed in favour of a simple list. This way it was possible to reduce the number of fields from nearly 50000 to 41. Please note: Due to the change of the mapping, the new index will no longer be compatible with the old one. A fresh index has to be populated. Signed-off-by: Max Magorsch <max@magorsch.de>
Diffstat (limited to 'app')
-rw-r--r--app/models/version.rb10
-rw-r--r--app/repositories/package_repository.rb24
-rw-r--r--app/views/packages/_metadata_use.html.erb2
-rw-r--r--app/views/packages/_useflag.html.erb4
-rw-r--r--app/views/packages/show.json.jbuilder14
5 files changed, 37 insertions, 17 deletions
diff --git a/app/models/version.rb b/app/models/version.rb
index 3629b98..429f4d1 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -165,14 +165,14 @@ class Version
private
def calc_useflags
- result = { local: {}, global: {}, use_expand: {} }
+ result = { local: [], global: [], use_expand: [] }
local_flag_map = UseflagRepository.local_for(atom.gsub("-#{version}", ''))
local_flags = local_flag_map.keys
use.sort.each do |flag|
if local_flags.include? flag
- result[:local][flag] = local_flag_map[flag].to_hsh
+ result[:local] << local_flag_map[flag].to_hsh
else
useflag = UseflagRepository.find_by(:name, flag)
@@ -180,11 +180,9 @@ class Version
next unless useflag
if useflag.scope == 'global'
- result[:global][useflag.name] = useflag.to_hsh
+ result[:global] << useflag.to_hsh
elsif useflag.scope == 'use_expand'
- prefix = useflag.use_expand_prefix.upcase
- result[:use_expand][prefix] ||= {}
- result[:use_expand][prefix][useflag.name.gsub(useflag.use_expand_prefix + '_', '')] = useflag.to_hsh
+ result[:use_expand] << useflag.to_hsh
end
end
end
diff --git a/app/repositories/package_repository.rb b/app/repositories/package_repository.rb
index ed77afb..bac4aec 100644
--- a/app/repositories/package_repository.rb
+++ b/app/repositories/package_repository.rb
@@ -26,7 +26,29 @@ class PackageRepository < BaseRepository
indexes :licenses, type: 'keyword'
indexes :herds, type: 'keyword'
indexes :maintainers, type: 'object'
- indexes :useflags, type: 'object'
+ indexes :useflags do
+ indexes :local do
+ indexes :scope, type: 'keyword'
+ indexes :name, type: 'keyword'
+ indexes :description, type: 'text'
+ indexes :atom, type: 'keyword'
+ indexes :use_expand_prefix, type: 'keyword'
+ end
+ indexes :global do
+ indexes :scope, type: 'keyword'
+ indexes :name, type: 'keyword'
+ indexes :description, type: 'text'
+ indexes :atom, type: 'keyword'
+ indexes :use_expand_prefix, type: 'keyword'
+ end
+ indexes :use_expand do
+ indexes :scope, type: 'keyword'
+ indexes :name, type: 'keyword'
+ indexes :description, type: 'text'
+ indexes :atom, type: 'keyword'
+ indexes :use_expand_prefix, type: 'keyword'
+ end
+ end
indexes :metadata_hash, type: 'keyword'
indexes :created_at, type: 'date'
indexes :updated_at, type: 'date'
diff --git a/app/views/packages/_metadata_use.html.erb b/app/views/packages/_metadata_use.html.erb
index d33b751..fdf2b0b 100644
--- a/app/views/packages/_metadata_use.html.erb
+++ b/app/views/packages/_metadata_use.html.erb
@@ -7,7 +7,7 @@
<%= render partial: 'useflag', object: useflags['global'], as: 'useflags' %>
<% end %>
<% unless useflags['use_expand'].empty? %>
- <% useflags['use_expand'].each_pair do |flag, values| %>
+ <% useflags['use_expand'].group_by { |u| u['use_expand_prefix'] }.each_pair do |flag, values| %>
<span class="kk-useflag-group"><%= t :use_expand_flag, flag: flag %></span>
<%= render partial: 'useflag', object: values, as: 'useflags' %>
<% end %>
diff --git a/app/views/packages/_useflag.html.erb b/app/views/packages/_useflag.html.erb
index a60e589..04ed0cd 100644
--- a/app/views/packages/_useflag.html.erb
+++ b/app/views/packages/_useflag.html.erb
@@ -1,5 +1,5 @@
<ul class="kk-useflag-container <%= useflags.size > 10 ? 'kk-useflag-container-many' : 'kk-useflag-container-few' %>">
-<% useflags.each_pair do |flag, flag_data| %>
- <li class="kk-useflag"><%= link_to flag, useflag_path(id: flag_data['name']), :title => strip_tags(flag_data['description']), 'data-toggle' => 'tooltip' %></li>
+<% useflags.each do |flag_data| %>
+ <li class="kk-useflag"><%= link_to flag_data['use_expand_prefix'].nil? ? flag_data['name'] : flag_data['name'].gsub(flag_data['use_expand_prefix'] + '_', '') , useflag_path(id: flag_data['name']), :title => strip_tags(flag_data['description']), 'data-toggle' => 'tooltip' %></li>
<% end %>
</ul>
diff --git a/app/views/packages/show.json.jbuilder b/app/views/packages/show.json.jbuilder
index 3b8a012..703ed8b 100644
--- a/app/views/packages/show.json.jbuilder
+++ b/app/views/packages/show.json.jbuilder
@@ -21,20 +21,20 @@ end
json.use do
json.local @package.versions.first.useflags[:local] do |flag|
- json.name flag[1][:name]
- json.description strip_tags flag[1][:description]
+ json.name flag[:name]
+ json.description strip_tags flag[:description]
end
json.global @package.versions.first.useflags[:global] do |flag|
- json.name flag[1][:name]
- json.description strip_tags flag[1][:description]
+ json.name flag[:name]
+ json.description strip_tags flag[:description]
end
- json.use_expand @package.versions.first.useflags[:use_expand] do |flag|
+ json.use_expand @package.versions.first.useflags[:use_expand].group_by { |u| u['use_expand_prefix'] } do |flag|
json.set! flag[0] do
json.array! flag[1] do |expand_flag|
- json.name expand_flag[0]
- json.description strip_tags expand_flag[1][:description]
+ json.name expand_flag[:name].gsub(expand_flag[:use_expand_prefix] + '_', '')
+ json.description strip_tags expand_flag[:description]
end
end
end