Bulk process when players join, if new missions are added.

This commit is contained in:
Sam 2018-07-04 14:08:16 +01:00 committed by Alexander Meech
parent 9509ae0672
commit 2bd4b1889b
2 changed files with 19 additions and 13 deletions

View File

@ -444,6 +444,7 @@ public class MissionManager extends MiniDbClientPlugin<MissionClient>
if (started > 0) if (started > 0)
{ {
player.sendMessage(F.main(getName(), "You started " + F.count(started) + " new mission" + (started == 1 ? "" : "s") + ". Visit " + NPC_NAME + C.mBody + " to view them.")); player.sendMessage(F.main(getName(), "You started " + F.count(started) + " new mission" + (started == 1 ? "" : "s") + ". Visit " + NPC_NAME + C.mBody + " to view them."));
runAsync(_repository::bulkProcess);
} }
} }

View File

@ -49,12 +49,14 @@ public class MissionRepository extends RepositoryBase
} }
private final List<MissionQuery> _queries; private final List<MissionQuery> _queries;
private final Object _lock;
MissionRepository() MissionRepository()
{ {
super(DBPool.getAccount()); super(DBPool.getAccount());
_queries = new ArrayList<>(); _queries = new ArrayList<>();
_lock = new Object();
} }
public void addQueryToQueue(MissionQuery query) public void addQueryToQueue(MissionQuery query)
@ -69,21 +71,24 @@ public class MissionRepository extends RepositoryBase
public void bulkProcess() public void bulkProcess()
{ {
if (_queries.isEmpty()) synchronized (_lock)
{ {
return; if (_queries.isEmpty())
{
return;
}
String sqlQuery = _queries.stream()
.map(query -> query._query)
.collect(Collectors.joining());
if (executeUpdate(sqlQuery) > 0)
{
_queries.forEach(query -> query._callback.run());
}
_queries.clear();
} }
String sqlQuery = _queries.stream()
.map(query -> query._query)
.collect(Collectors.joining());
if (executeUpdate(sqlQuery) > 0)
{
_queries.forEach(query -> query._callback.run());
}
_queries.clear();
} }
public boolean completeMission(int accountId, int missionId) public boolean completeMission(int accountId, int missionId)