Use redis pipeline for community player statuses
This commit is contained in:
parent
08d65f3662
commit
73cefb69c9
@ -2,14 +2,17 @@ package mineplex.core.communities.storage;
|
|||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.common.timing.TimingManager;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.communities.Community;
|
import mineplex.core.communities.Community;
|
||||||
import mineplex.core.communities.CommunityJoinRequestInfo;
|
import mineplex.core.communities.CommunityJoinRequestInfo;
|
||||||
@ -91,11 +94,6 @@ public class CommunityRepository extends MinecraftRepository
|
|||||||
boolean readingChat = memberSet.getBoolean("readingChat");
|
boolean readingChat = memberSet.getBoolean("readingChat");
|
||||||
|
|
||||||
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, lastLogin);
|
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, lastLogin);
|
||||||
PlayerStatus status = _repo.getElement(name.toLowerCase());
|
|
||||||
if (status != null)
|
|
||||||
{
|
|
||||||
info.update(lastLogin, true, status.getServer());
|
|
||||||
}
|
|
||||||
info.ReadingChat = readingChat;
|
info.ReadingChat = readingChat;
|
||||||
|
|
||||||
Community community = communityMap.get(communityId);
|
Community community = communityMap.get(communityId);
|
||||||
@ -152,11 +150,16 @@ public class CommunityRepository extends MinecraftRepository
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
TimingManager.start("member elements");
|
||||||
for (Community c : communities)
|
for (Community c : communities)
|
||||||
{
|
{
|
||||||
for (CommunityMemberInfo info : c.getMembers().values())
|
List<CommunityMemberInfo> members = new ArrayList<>(c.getMembers().values());
|
||||||
|
List<PlayerStatus> statuses = _repo.getElementsSequential(members.stream().map(info -> info.UUID.toString()).collect(Collectors.toList()));
|
||||||
|
for (int i = 0; i < members.size(); i++)
|
||||||
{
|
{
|
||||||
PlayerStatus status = _repo.getElement(info.UUID.toString());
|
CommunityMemberInfo info = members.get(i);
|
||||||
|
PlayerStatus status = statuses.get(i);
|
||||||
|
|
||||||
boolean online = false;
|
boolean online = false;
|
||||||
String server = "";
|
String server = "";
|
||||||
if (status != null)
|
if (status != null)
|
||||||
@ -178,6 +181,7 @@ public class CommunityRepository extends MinecraftRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TimingManager.stop("member elements");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateJoinRequests(LinkedList<Community> communities)
|
public void updateJoinRequests(LinkedList<Community> communities)
|
||||||
@ -186,11 +190,16 @@ public class CommunityRepository extends MinecraftRepository
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
TimingManager.start("request elements");
|
||||||
for (Community c : communities)
|
for (Community c : communities)
|
||||||
{
|
{
|
||||||
for (CommunityJoinRequestInfo info : c.getJoinRequests().values())
|
List<CommunityJoinRequestInfo> requests = new ArrayList<>(c.getJoinRequests().values());
|
||||||
|
List<PlayerStatus> statuses = _repo.getElementsSequential(requests.stream().map(info -> info.UUID.toString()).collect(Collectors.toList()));
|
||||||
|
for (int i = 0; i < requests.size(); i++)
|
||||||
{
|
{
|
||||||
PlayerStatus status = _repo.getElement(info.UUID.toString());
|
CommunityJoinRequestInfo info = requests.get(i);
|
||||||
|
PlayerStatus status = statuses.get(i);
|
||||||
|
|
||||||
if (status != null)
|
if (status != null)
|
||||||
{
|
{
|
||||||
if (!info.Name.equals(status.getName()))
|
if (!info.Name.equals(status.getName()))
|
||||||
@ -200,6 +209,7 @@ public class CommunityRepository extends MinecraftRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TimingManager.stop("request elements");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadInvites(int accountId, List<Integer> invites)
|
public void loadInvites(int accountId, List<Integer> invites)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package mineplex.serverdata.data;
|
package mineplex.serverdata.data;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DataRepository is used to store {@link Data} objects in a central database
|
* DataRepository is used to store {@link Data} objects in a central database
|
||||||
@ -18,6 +19,8 @@ public interface DataRepository<T extends Data>
|
|||||||
|
|
||||||
public Collection<T> getElements(Collection<String> dataIds);
|
public Collection<T> getElements(Collection<String> dataIds);
|
||||||
|
|
||||||
|
public List<T> getElementsSequential(List<String> dataIds);
|
||||||
|
|
||||||
public void addElement(T element, int timeout);
|
public void addElement(T element, int timeout);
|
||||||
|
|
||||||
public void addElement(T element);
|
public void addElement(T element);
|
||||||
|
@ -102,7 +102,37 @@ public class RedisDataRepository<T extends Data> extends RedisRepository impleme
|
|||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<T> getElementsSequential(List<String> dataIds)
|
||||||
|
{
|
||||||
|
List<T> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
try(Jedis jedis = getResource(false))
|
||||||
|
{
|
||||||
|
Pipeline pipeline = jedis.pipelined();
|
||||||
|
|
||||||
|
List<Response<String>> responses = new ArrayList<>();
|
||||||
|
for (String dataId : dataIds)
|
||||||
|
{
|
||||||
|
responses.add(pipeline.get(generateKey(dataId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block until all requests have received pipelined responses
|
||||||
|
pipeline.sync();
|
||||||
|
|
||||||
|
for (Response<String> response : responses)
|
||||||
|
{
|
||||||
|
String serializedData = response.get();
|
||||||
|
T element = deserialize(serializedData);
|
||||||
|
|
||||||
|
elements.add(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T getElement(String dataId)
|
public T getElement(String dataId)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user