mirror of https://github.com/tasks/tasks
Add SyncThrottle
parent
886e22f791
commit
61ff44a6ed
@ -0,0 +1,26 @@
|
|||||||
|
package com.todoroo.astrid.service;
|
||||||
|
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class SyncThrottle {
|
||||||
|
|
||||||
|
private final Map<Long, DateTime> lastSync = new HashMap<>();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public SyncThrottle() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean canSync(long listId) {
|
||||||
|
DateTime now = new DateTime();
|
||||||
|
DateTime last = lastSync.get(listId);
|
||||||
|
lastSync.put(listId, now);
|
||||||
|
return last == null || last.isBefore(now.minusMinutes(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue