Fix cache invalidation when group data changes (#1010)

This commit is contained in:
Luck 2018-05-21 18:48:47 +01:00
parent f4882c1c14
commit a90e59ec97
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 24 additions and 16 deletions

View File

@ -77,21 +77,21 @@ public abstract class AbstractConnectionListener implements ConnectionListener {
User user = this.plugin.getStorage().loadUser(u, username).join();
if (user == null) {
throw new NullPointerException("User is null");
} else {
// Setup defaults for the user
boolean save = false;
for (AssignmentRule rule : this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_ASSIGNMENTS)) {
if (rule.apply(user)) {
save = true;
}
}
}
// If they were given a default, persist the new assignments back to the storage.
if (save) {
this.plugin.getStorage().saveUser(user).join();
// Setup defaults for the user
boolean save = false;
for (AssignmentRule rule : this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_ASSIGNMENTS)) {
if (rule.apply(user)) {
save = true;
}
}
// If they were given a default, persist the new assignments back to the storage.
if (save) {
this.plugin.getStorage().saveUser(user).join();
}
final long time = System.currentTimeMillis() - startTime;
if (time >= 1000) {
this.plugin.getLogger().warn("Processing login for " + username + " took " + time + "ms.");

View File

@ -80,6 +80,11 @@ public class AbstractStorage implements Storage {
return this.dao;
}
@Override
public ApiStorage getApiDelegate() {
return this.apiDelegate;
}
private <T> CompletableFuture<T> makeFuture(Callable<T> supplier) {
return CompletableFuture.supplyAsync(() -> {
try {
@ -102,11 +107,6 @@ public class AbstractStorage implements Storage {
}, this.dao.getPlugin().getBootstrap().getScheduler().async());
}
@Override
public ApiStorage getApiDelegate() {
return this.apiDelegate;
}
private interface ThrowingRunnable {
void run() throws Exception;
}

View File

@ -203,6 +203,7 @@ public abstract class AbstractConfigurateDao extends AbstractDao {
} catch (Exception e) {
throw reportException(uuid.toString(), e);
} finally {
user.invalidateCachedData();
user.getIoLock().unlock();
}
return user;
@ -258,6 +259,7 @@ public abstract class AbstractConfigurateDao extends AbstractDao {
} catch (Exception e) {
throw reportException(name, e);
} finally {
group.invalidateCachedData();
group.getIoLock().unlock();
}
return group;
@ -290,6 +292,7 @@ public abstract class AbstractConfigurateDao extends AbstractDao {
throw reportException(name, e);
} finally {
if (group != null) {
group.invalidateCachedData();
group.getIoLock().unlock();
}
}

View File

@ -286,6 +286,7 @@ public class MongoDao extends AbstractDao {
}
}
} finally {
user.invalidateCachedData();
user.getIoLock().unlock();
}
return user;
@ -356,6 +357,7 @@ public class MongoDao extends AbstractDao {
}
}
} finally {
group.invalidateCachedData();
group.getIoLock().unlock();
}
return group;
@ -385,6 +387,7 @@ public class MongoDao extends AbstractDao {
}
} finally {
if (group != null) {
group.invalidateCachedData();
group.getIoLock().unlock();
}
}

View File

@ -355,6 +355,7 @@ public class SqlDao extends AbstractDao {
}
}
} finally {
user.invalidateCachedData();
user.getIoLock().unlock();
}
return user;
@ -596,6 +597,7 @@ public class SqlDao extends AbstractDao {
group.clearNodes();
}
} finally {
group.invalidateCachedData();
group.getIoLock().unlock();
}
return Optional.of(group);