mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
Squeezed the last bits I possibly can out of the Lua implementation.
Performance enhancements beyond what I've done are welcome.
This commit is contained in:
parent
a6ab874791
commit
d54238023d
@ -30,7 +30,6 @@ import com.google.common.base.Functions;
|
|||||||
import com.google.common.collect.*;
|
import com.google.common.collect.*;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||||
import com.imaginarycode.minecraft.redisbungee.util.LuaManager;
|
import com.imaginarycode.minecraft.redisbungee.util.LuaManager;
|
||||||
import com.imaginarycode.minecraft.redisbungee.util.NameFetcher;
|
import com.imaginarycode.minecraft.redisbungee.util.NameFetcher;
|
||||||
@ -55,7 +54,6 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
|
|||||||
import redis.clients.jedis.exceptions.JedisException;
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -138,13 +136,22 @@ public final class RedisBungee extends Plugin {
|
|||||||
|
|
||||||
final Multimap<String, UUID> serversToPlayers() {
|
final Multimap<String, UUID> serversToPlayers() {
|
||||||
if (usingLua) {
|
if (usingLua) {
|
||||||
String string = (String) serverToPlayersScript.eval(ImmutableList.<String>of(), getServerIds());
|
Collection<String> data = (Collection<String>) serverToPlayersScript.eval(ImmutableList.<String>of(), getServerIds());
|
||||||
Map<String, Set<UUID>> deserialized = gson.fromJson(string, new TypeToken<Map<String, Set<UUID>>>() {}.getType());
|
|
||||||
|
|
||||||
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
||||||
|
|
||||||
for (Map.Entry<String, Set<UUID>> entry : deserialized.entrySet()) {
|
// TODO: This seems pretty slow, but execution times over the long term seem to stay below that of the
|
||||||
builder.putAll(entry.getKey(), entry.getValue());
|
// Java implementation, at least. If you have a better idea, I want to see it!
|
||||||
|
String key = null;
|
||||||
|
|
||||||
|
for (String s : data) {
|
||||||
|
if (key == null) {
|
||||||
|
key = s;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.put(key, UUID.fromString(s));
|
||||||
|
key = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
-- This script needs all active proxies available specified as args.
|
|
||||||
local insert = table.insert
|
|
||||||
local call = redis.call
|
local call = redis.call
|
||||||
|
|
||||||
local serverToData = {}
|
local serverToData = {}
|
||||||
@ -9,15 +7,11 @@ for _, proxy in ipairs(ARGV) do
|
|||||||
for _, player in ipairs(players) do
|
for _, player in ipairs(players) do
|
||||||
local server = call("HGET", "player:" .. player, "server")
|
local server = call("HGET", "player:" .. player, "server")
|
||||||
if server then
|
if server then
|
||||||
local map = serverToData[server]
|
local sz = #serverToData
|
||||||
if not map then
|
serverToData[sz + 1] = server
|
||||||
map = {}
|
serverToData[sz + 2] = player
|
||||||
serverToData[server] = map
|
|
||||||
end
|
|
||||||
insert(map, player)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Redis can't map Lua associative tables back, so we have to send it as JSON.
|
return serverToData
|
||||||
return cjson.encode(serverToData)
|
|
Loading…
Reference in New Issue
Block a user