Skip to content

Commit

Permalink
Merge pull request traccar#3406 from Abyss777/fix_unknown_uniqueid
Browse files Browse the repository at this point in the history
Fix retrieving objects by unknown tokens/uniqueId
  • Loading branch information
tananaev authored Aug 2, 2017
2 parents 237c802 + 75374d6 commit d44c9c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/org/traccar/database/DriversManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class DriversManager extends ExtendedObjectManager<Driver> {

private Map<String, Long> driversByUniqueId;
private Map<String, Driver> driversByUniqueId;

public DriversManager(DataManager dataManager) {
super(dataManager, Driver.class);
Expand All @@ -36,7 +36,7 @@ private void putUniqueDriverId(Driver driver) {
if (driversByUniqueId == null) {
driversByUniqueId = new ConcurrentHashMap<>(getAllItems().size());
}
driversByUniqueId.put(driver.getUniqueId(), driver.getId());
driversByUniqueId.put(driver.getUniqueId(), driver);
}

@Override
Expand Down Expand Up @@ -68,6 +68,6 @@ protected void removeCachedItem(long driverId) {
}

public Driver getDriverByUniqueId(String uniqueId) {
return getById(driversByUniqueId.get(uniqueId));
return driversByUniqueId.get(uniqueId);
}
}
10 changes: 4 additions & 6 deletions src/org/traccar/database/UsersManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class UsersManager extends SimpleObjectManager<User> {

private Map<String, Long> usersTokens;
private Map<String, User> usersTokens;

public UsersManager(DataManager dataManager) {
super(dataManager, User.class);
Expand All @@ -39,7 +39,7 @@ private void putToken(User user) {
usersTokens = new ConcurrentHashMap<>();
}
if (user.getToken() != null) {
usersTokens.put(user.getToken(), user.getId());
usersTokens.put(user.getToken(), user);
}
}

Expand All @@ -53,9 +53,7 @@ protected void addNewItem(User user) {
protected void updateCachedItem(User user) {
User cachedUser = getById(user.getId());
super.updateCachedItem(user);
if (user.getToken() != null) {
usersTokens.put(user.getToken(), user.getId());
}
putToken(user);
if (cachedUser.getToken() != null && !cachedUser.getToken().equals(user.getToken())) {
usersTokens.remove(cachedUser.getToken());
}
Expand All @@ -82,7 +80,7 @@ public Set<Long> getManagedItems(long userId) {
}

public User getUserByToken(String token) {
return getById(usersTokens.get(token));
return usersTokens.get(token);
}

}

0 comments on commit d44c9c7

Please sign in to comment.