Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all about caching except renew #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,7 @@
# this re-opened class contains all wingolf-specific additions to the group model.

class Group

# This method is called by a nightly rake task to renew the cache of this object.
#
def fill_cache

# Memberships
memberships_for_member_list
memberships_this_year
latest_memberships

# Other Groups
leaf_groups
corporation

# Address Labels
members_postal_addresses
cached_members_postal_addresses_created_at

end



# Special Groups
# ==========================================================================================
Expand Down
5 changes: 0 additions & 5 deletions app/models/user_group_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
#
class UserGroupMembership

# This method is called by a nightly rake task to renew the cache of this object.
#
def fill_cache
valid_from
end

end

18 changes: 18 additions & 0 deletions vendor/engines/your_platform/app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ def delete_cache
ancestor_groups(true).each { |g| g.delete_cached(:leaf_groups); g.delete_cached(:status_groups) }
end

# This method is called by a nightly rake task to renew the cache of this object.
#
def fill_cache
# from GroupMixins::Memberships
memberships_for_member_list
memberships_for_member_list_count
latest_memberships
memberships_this_year

# Other Groups
leaf_groups
corporation

# Address Labels
members_postal_addresses
cached_members_postal_addresses_created_at
end

# General Properties
# ==========================================================================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def corporations
# Find corporation groups of a certain user.
#
def find_corporation_groups_of( user )
ancestor_groups_of_user = user.groups
ancestor_groups_of_user = user.ancestor_groups
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vorsicht: groups sind alle aktuellen Gruppen, ancestor_groups auch die Gruppen, in denen der Benutzer einmal Mitglied war, weil ancestor_groups direkt durch die DAG-Structure geht. groups ist hier definiert: ./vendor/engines/your_platform/app/models/user_mixins/memberships.rb:52

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vermutlich wäre user.groups(true) die richtige Lösung. Die Frage ist, wo man es einfügt.

corporation_groups = Group.find_corporation_groups if Group.find_corporations_parent_group
return ancestor_groups_of_user & corporation_groups if ancestor_groups_of_user and corporation_groups
end
Expand Down Expand Up @@ -112,7 +112,7 @@ def find_corporations_branch_groups
# are displayed separately.
#
def find_corporations_branch_groups_of( user )
ancestor_groups = user.groups
ancestor_groups = user.ancestor_groups
corporations_branch = self.find_corporations_branch_groups
return ancestor_groups & corporations_branch if ancestor_groups and corporations_branch
end
Expand All @@ -127,7 +127,7 @@ def find_corporations_branch_groups_of( user )
# in the groups list, e.g. attendee groups of corporation events.
#
def find_non_corporations_branch_groups_of( user )
ancestor_groups = user.groups
ancestor_groups = user.ancestor_groups
corporations_branch = self.find_corporations_branch_groups
corporations_branch = [] unless corporations_branch
return ancestor_groups -
Expand Down
3 changes: 2 additions & 1 deletion vendor/engines/your_platform/app/models/profile_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ def value
# Overwrite save to ensure that the cache is deleted in case of changes.
#
def save( *args )
result = super( *args )
delete_cache
super( *args )
result
end

def delete_cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ module StructureableMixins::Roles
end

def fill_cache
super
super if defined?(super)
if respond_to?(:child_groups) # TODO: Refactor this. It should be possible to find the admins for a user.
find_admins
admins_of_ancestors
admins_of_self_and_ancestors
officers_of_self_and_parent_groups
officers_groups_of_self_and_descendant_groups
find_officers
officers_of_ancestors
officers_of_ancestor_groups
officers_of_self_and_ancestors
officers_of_self_and_ancestor_groups
find_admins
admins_of_ancestors
admins_of_ancestor_groups
admins_of_self_and_ancestors
end
end

Expand Down Expand Up @@ -115,7 +119,11 @@ def direct_officers

def officers_of_self_and_parent_groups
cached do
direct_officers + (parent_groups.collect { |parent_group| parent_group.direct_officers }.flatten)
if defined? parent_groups
direct_officers + (parent_groups.collect { |parent_group| parent_group.direct_officers }.flatten)
else
direct_officers
end
end
end

Expand All @@ -140,7 +148,13 @@ def officers_of_ancestors
end

def officers_of_ancestor_groups
cached { ancestor_groups.collect { |ancestor| ancestor.find_officers }.flatten }
cached do
if defined? ancestor_groups
ancestor_groups.collect { |ancestor| ancestor.find_officers }.flatten
else
[]
end
end
end

def officers_of_self_and_ancestors
Expand Down Expand Up @@ -182,15 +196,17 @@ def find_admins_parent_group
end

def create_admins_parent_group
result = create_special_group(:admins_parent, parent_element: find_or_create_officers_parent_group )
delete_cached(:find_admins)
create_special_group(:admins_parent, parent_element: find_or_create_officers_parent_group )
result
end

def find_or_create_admins_parent_group
find_special_group(:admins_parent, parent_element: find_or_create_officers_parent_group) or
begin
result = create_special_group(:admins_parent, parent_element: find_or_create_officers_parent_group)
delete_cached(:find_admins)
create_special_group(:admins_parent, parent_element: find_or_create_officers_parent_group)
result
rescue
nil
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class UserGroupMembership < DagLink
may_need_review
attr_accessible :needs_review

# This method is called by a nightly rake task to renew the cache of this object.
#
def fill_cache
# from UserGroupMembershipMixins::ValidityRangeForIndirectMemberships
valid_from
end

# General Properties
# ====================================================================================================
Expand Down