Foren

Problem UserPersistence.containsRole(long pk, long rolePK)

Jiri Mecner, geändert vor 9 Jahren.

Problem UserPersistence.containsRole(long pk, long rolePK)

New Member Beiträge: 3 Beitrittsdatum: 04.03.13 Neueste Beiträge
Hi, I founded that UserPersistenceImpl use ReverseTableMapper for checking whether user has a specific role. ReverseTableMapper make a "select userid from users_roles where roleid = ?". Unfortunately we have a three milion users. When portal checks whether user has a role "User" it fetches 3 milion user ids from db, which is heavy for db and takes a long lime.

I reimplemented TableMapperFactory and created a not reversed TableMaper. Is it a correct solution?


	public static
		<l extends basemodel<l>, R extends BaseModel<r>&gt; TableMapper<l, r>
			getTableMapper(
				String tableName, String leftColumnName, String rightColumnName,
				BasePersistence<l> leftPersistence,
				BasePersistence<r> rightPersistence) {

		// Use not reversed TableMaper
		if("Users_Roles".equals(tableName)){
			return new TableMapperImpl<l, r>(tableName, leftColumnName, rightColumnName, leftPersistence, rightPersistence);
		}

		TableMapper<!--?, ?--> tableMapper = tableMappers.get(tableName);

		if (tableMapper == null) {
			TableMapperImpl<l, r> tableMapperImpl =
				new TableMapperImpl<l, r>(
					tableName, leftColumnName, rightColumnName, leftPersistence,
					rightPersistence);

			tableMapperImpl.setReverseTableMapper(
				new ReverseTableMapper<r, l>(tableMapperImpl));

			tableMapper = tableMapperImpl;

			tableMappers.put(tableName, tableMapper);
		}
		else if (!tableMapper.matches(leftColumnName, rightColumnName)) {
			tableMapper = tableMapper.getReverseTableMapper();
		}

		return (TableMapper<l, r>)tableMapper;
	}
</l,></r,></l,></l,></l,></r></l></l,></r></l>


Thank you for answer.
Diego Carmo, geändert vor 7 Jahren.

RE: Problem UserPersistence.containsRole(long pk, long rolePK)

New Member Beiträge: 2 Beitrittsdatum: 19.11.13 Neueste Beiträge
Hello, I recently had the same problem of performance on the users.
Your solution solved the problem, managed to deploy?
Grateful.