I wasn’t sure if I should post this within the Plugin Development category, or Plugin Support. If this is in the wrong location, feel free to move it! 
I’m developing a plugin which is fairly simple, but there’s a slightly complex logical situation of how to keep the Server/Source data consistent with each other.
I’ve created a Gist which outlines the current method, as well as the source code for said Method.
The Gist contains the MySQLManager. however, ManagerTypes are modular, and easily swapped around. Currently, the only thing each ManagerType contributes to this method is the actual grabbing of a list of whitelisted users, via Manager#getWhitelistFromSource. The rest is handled within the ManagerBase.
TL;DR, take a look at the link above, and help me think of a better way to do this!
EDIT: Links were broken. Fixed them.
Thanks @thomas15v for informing me about it.
Describe what you are trying to do.
Do you want to make a white list plugin with a MySQL data store, so that you can use a PHP script to add players to it?
If there are just a few logins per minute and if the database connection is fast, you don’t really need a cache for your list. You can just call the database when a player logs in.
If you want to improve your code (edit: the performance), use jdbc batching.
2 Likes
[quote=“boformer, post:2, topic:3916”]
Describe what you are trying to do.
[/quote]GrimList is just supposed to be an easy-to-use, easy-to-setup, but powerful, modular whitelisting plugin. MySQL is just one of the modules, and the best to use for this example, as it’s one of the most likely to be modified outside of using in-game commands (thus, the necessity of keeping data consistent between the Server and Source).
I plan to have module to module conversions, but that’s neither here nor there, at the moment.
[quote=“boformer, post:2, topic:3916”]
Do you want to make a white list plugin with a MySQL data store, so that you can use a PHP script to add players to it?
[/quote]Sure, but that’s not where my issue arises. 
[quote=“boformer, post:2, topic:3916”]
If there are just a few logins per minute and if the database connection is fast, you don’t really need a cache for your list. You can just call the database when a player logs in.
[/quote] If this plugin was for my own personal use, and I knew its projected use, I’d probably agree with you. However, as a plugin that is intended to be used by others, I’m kind of just trying to make the smallest footprint possible. As I can’t estimate how many logins their would be per minute or the database connectivity of a server not owned by myself, I have to plan for the worst. 
[quote=“boformer, post:2, topic:3916”]
If you want to improve your code (edit: the performance), use jdbc batching.
[/quote]I’ll look into this. 
To streamline your code (not really improving performance), you can use a chain system:
Remove all the ‘source’ methods in your Manager class
Make 2 Manager classes:
CachedManager
MySQLManager
CachedManager
:
additional methods:
setSource(Manager manager)
-
fetchListFromSource()
or syncWithSource()
: Calls updateList
method, caches the result.
- the auto update task ‘serverSync’ methods you had.
The initialize
and shutdown
get passed through to the source manager.
This class uses an internal List
for caching. If you also want to use a cache for adding/removing, add more lists.
MySQLManager
This class directly calls the database, no cache.
streamlined Manager Interface
public interface Manager {
public List<UUID> getWhitelist();
public boolean isWhitelisted(UUID uuid);
public void add(UUID uuid);
public void remove(UUID uuid);
//takes 2 lists, returns new whitelist. Use a single batch in MySQLManager
public List<UUID> updateWhitelist(List<UUID> addition, List<UUID> removal)
public void initialize();
public void shutdown();
}
public interface CachedManager extends Manager {
public void setSource(Manager manager)
public void syncWithSource()
//the auto update task 'serverSync' methods you had.
}
1 Like
No. lol. Not something I’m interested in.
You don’t want to make the getting and setting of MySQL easier?
I’m more comfortable and confident in my own methods.