aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-06-15 14:22:23 +0500
committerAbyss777 <abyss@fox5.ru>2016-06-15 14:22:23 +0500
commitf08bb5adf425269a00e760c669bdeeadc8c7e112 (patch)
treec2215abadf212d5e56def143e906683f8390f677 /src/org/traccar/database
parent8ddcc66dc6441ce8f8a122d09872c143922fa0f0 (diff)
downloadtraccar-server-f08bb5adf425269a00e760c669bdeeadc8c7e112.tar.gz
traccar-server-f08bb5adf425269a00e760c669bdeeadc8c7e112.tar.bz2
traccar-server-f08bb5adf425269a00e760c669bdeeadc8c7e112.zip
- Work only with cached devices from everywhere
- Some optimization
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DataManager.java25
-rw-r--r--src/org/traccar/database/GeofenceManager.java2
-rw-r--r--src/org/traccar/database/PermissionsManager.java2
3 files changed, 26 insertions, 3 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index a32d31d68..f5df1b84b 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -342,11 +342,34 @@ public class DataManager implements IdentityManager {
.executeQuery(GroupPermission.class);
}
- public Collection<Device> getAllDevices() throws SQLException {
+ private Collection<Device> getAllDevices() throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectDevicesAll"))
.executeQuery(Device.class);
}
+ public Collection<Device> getAllDevicesCached() {
+ boolean forceUpdate;
+ devicesLock.readLock().lock();
+ try {
+ forceUpdate = devicesById.values().isEmpty();
+ } finally {
+ devicesLock.readLock().unlock();
+ }
+
+ try {
+ updateDeviceCache(forceUpdate);
+ } catch (SQLException e) {
+ Log.warning(e);
+ }
+
+ devicesLock.readLock().lock();
+ try {
+ return devicesById.values();
+ } finally {
+ devicesLock.readLock().unlock();
+ }
+ }
+
public Collection<Device> getDevices(long userId) throws SQLException {
Collection<Device> devices = new ArrayList<>();
for (long id : Context.getPermissionsManager().getDevicePermissions(userId)) {
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
index b551bc467..0119a62ca 100644
--- a/src/org/traccar/database/GeofenceManager.java
+++ b/src/org/traccar/database/GeofenceManager.java
@@ -113,7 +113,7 @@ public class GeofenceManager {
.add(deviceGeofence.getGeofenceId());
}
- for (Device device : dataManager.getAllDevices()) {
+ for (Device device : dataManager.getAllDevicesCached()) {
long groupId = device.getGroupId();
while (groupId != 0) {
getDeviceGeofences(deviceGeofencesWithGroups,
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 96a6488ef..b6dd2e2a9 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -78,7 +78,7 @@ public class PermissionsManager {
users.put(user.getId(), user);
}
- GroupTree groupTree = new GroupTree(dataManager.getAllGroups(), dataManager.getAllDevices());
+ GroupTree groupTree = new GroupTree(dataManager.getAllGroups(), dataManager.getAllDevicesCached());
for (GroupPermission permission : dataManager.getGroupPermissions()) {
Set<Long> userGroupPermissions = getGroupPermissions(permission.getUserId());
Set<Long> userDevicePermissions = getDevicePermissions(permission.getUserId());