Bulk process when players join, if new missions are added.
This commit is contained in:
parent
9509ae0672
commit
2bd4b1889b
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user