Skip to content

Commit

Permalink
Merge pull request keycloak#4574 from patriot1burke/master
Browse files Browse the repository at this point in the history
KEYCLOAK-5701
  • Loading branch information
patriot1burke authored Oct 19, 2017
2 parents 00ea849 + 8faa6f1 commit 0371a56
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.keycloak.models.cache.infinispan.events.InvalidationEvent;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import org.keycloak.models.cache.infinispan.events.RealmCacheInvalidationEvent;
import org.keycloak.models.cache.infinispan.stream.GroupListPredicate;
import org.keycloak.models.cache.infinispan.stream.HasRolePredicate;
import org.keycloak.models.cache.infinispan.stream.InClientPredicate;
import org.keycloak.models.cache.infinispan.stream.InRealmPredicate;
Expand Down Expand Up @@ -72,8 +73,7 @@ public void roleRemoval(String id, String roleName, String roleContainerId, Set<
}

public void groupQueriesInvalidations(String realmId, Set<String> invalidations) {
invalidations.add(RealmCacheSession.getGroupsQueryCacheKey(realmId));
invalidations.add(RealmCacheSession.getTopGroupsQueryCacheKey(realmId)); // Just easier to always invalidate top-level too. It's not big performance penalty
addInvalidations(GroupListPredicate.create().realm(realmId), invalidations);
}

public void clientAdded(String realmId, String clientUUID, String clientId, Set<String> invalidations) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.keycloak.models.cache.infinispan.stream;

import org.keycloak.models.cache.infinispan.entities.GroupListQuery;
import org.keycloak.models.cache.infinispan.entities.Revisioned;

import java.io.Serializable;
import java.util.Map;
import java.util.function.Predicate;

/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class GroupListPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String realm;

public static GroupListPredicate create() {
return new GroupListPredicate();
}

public GroupListPredicate realm(String realm) {
this.realm = realm;
return this;
}

@Override
public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue();
if (value == null) return false;
if (value instanceof GroupListQuery) {
GroupListQuery groupList = (GroupListQuery)value;
if (groupList.getRealm().equals(realm)) return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,6 @@ module.config([ '$routeProvider', function($routeProvider) {
resolve : {
realm : function(RealmLoader) {
return RealmLoader();
},
groups : function(GroupListLoader) {
return GroupListLoader();
},
groupsCount : function(GroupCountLoader) {
return GroupCountLoader();
}
},
controller : 'GroupListCtrl'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
module.controller('GroupListCtrl', function($scope, $route, $q, realm, groups, groupsCount, Groups, GroupsCount, Group, GroupChildren, Notifications, $location, Dialog) {
module.controller('GroupListCtrl', function($scope, $route, $q, realm, Groups, GroupsCount, Group, GroupChildren, Notifications, $location, Dialog) {
$scope.realm = realm;
$scope.groupList = [
{
"id" : "realm",
"name": "Groups",
"subGroups" : groups
"subGroups" : []
}
];


$scope.searchTerms = '';
$scope.currentPage = 1;
$scope.currentPageInput = $scope.currentPage;
$scope.pageSize = groups.length;
$scope.numberOfPages = Math.ceil(groupsCount.count/$scope.pageSize);

$scope.pageSize = 20;
$scope.tree = [];

var refreshGroups = function (search) {
console.log('refreshGroups');

var first = ($scope.currentPage * $scope.pageSize) - $scope.pageSize;
console.log('first:' + first);
var queryParams = {
realm : realm.id,
first : ($scope.currentPage * $scope.pageSize) - $scope.pageSize,
first : first,
max : $scope.pageSize
};
var countParams = {
Expand All @@ -38,8 +41,9 @@ module.controller('GroupListCtrl', function($scope, $route, $q, realm, groups, g
}, function() {
promiseGetGroups.reject('Unable to fetch ' + queryParams);
});
var promiseGetGroupsChain = promiseGetGroups.promise.then(function(entry) {
groups = entry;
var promiseGetGroupsChain = promiseGetGroups.promise.then(function(groups) {
console.log('*** group call groups size: ' + groups.length);
console.log('*** group call groups size: ' + groups.length);
$scope.groupList = [
{
"id" : "realm",
Expand All @@ -55,11 +59,11 @@ module.controller('GroupListCtrl', function($scope, $route, $q, realm, groups, g
}, function() {
promiseCount.reject('Unable to fetch ' + countParams);
});
var promiseCountChain = promiseCount.promise.then(function(entry) {
groupsCount = entry;
var promiseCountChain = promiseCount.promise.then(function(groupsCount) {
$scope.numberOfPages = Math.ceil(groupsCount.count/$scope.pageSize);
});
});
};
refreshGroups();

$scope.$watch('currentPage', function(newValue, oldValue) {
if(newValue !== oldValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,7 @@ module.factory('AuthenticationConfigLoader', function(Loader, AuthenticationConf
module.factory('GroupListLoader', function(Loader, Groups, $route, $q) {
return Loader.query(Groups, function() {
return {
realm : $route.current.params.realm,
first : 0,
max : 20
realm : $route.current.params.realm
}
});
});
Expand Down

0 comments on commit 0371a56

Please sign in to comment.