mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-27 11:19:21 +00:00
Fast job sorting.
This commit is contained in:

committed by
Greyson Parrelli

parent
60a701f84f
commit
373972f5dc
@@ -105,9 +105,25 @@ public class FastJobStorage implements JobStorage {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
return Stream.of(jobs)
|
return Stream.of(jobs)
|
||||||
|
.groupBy(jobSpec -> {
|
||||||
|
String queueKey = jobSpec.getQueueKey();
|
||||||
|
if (queueKey != null) {
|
||||||
|
return queueKey;
|
||||||
|
} else {
|
||||||
|
return jobSpec.getId();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(byQueueKey ->
|
||||||
|
Stream.of(byQueueKey.getValue()).sorted((j1, j2) -> Long.compare(j1.getCreateTime(), j2.getCreateTime()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null)
|
||||||
|
)
|
||||||
|
.withoutNulls()
|
||||||
|
.filter(j -> {
|
||||||
|
List<DependencySpec> dependencies = dependenciesByJobId.get(j.getId());
|
||||||
|
return dependencies == null || dependencies.isEmpty();
|
||||||
|
})
|
||||||
.filterNot(JobSpec::isRunning)
|
.filterNot(JobSpec::isRunning)
|
||||||
.filter(this::firstInQueue)
|
|
||||||
.filter(j -> !dependenciesByJobId.containsKey(j.getId()) || dependenciesByJobId.get(j.getId()).isEmpty())
|
|
||||||
.filter(j -> j.getNextRunAttemptTime() <= currentTime)
|
.filter(j -> j.getNextRunAttemptTime() <= currentTime)
|
||||||
.sorted((j1, j2) -> Long.compare(j1.getCreateTime(), j2.getCreateTime()))
|
.sorted((j1, j2) -> Long.compare(j1.getCreateTime(), j2.getCreateTime()))
|
||||||
.toList();
|
.toList();
|
||||||
|
Reference in New Issue
Block a user