storageForUser returns the username and storage items for a given userId, preferring the in-memory copy for online users and falling back to disk for offline ones.
(userId int)
| 126 | // storageForUser returns the username and storage items for a given userId, |
| 127 | // preferring the in-memory copy for online users and falling back to disk for offline ones. |
| 128 | func (m *StorageModule) storageForUser(userId int) (username string, storageItems []items.Item) { |
| 129 | if u := users.GetByUserId(userId); u != nil { |
| 130 | data := m.storage[userId] |
| 131 | return u.Username, data.getItems() |
| 132 | } |
| 133 | // Offline: find username from index then load from disk. |
| 134 | idx := users.GetUserIndex() |
| 135 | if name, ok := idx.FindByUserId(userId); ok { |
| 136 | username = name |
| 137 | } |
| 138 | offlineData := m.load(userId) |
| 139 | return username, offlineData.getItems() |
| 140 | } |
no test coverage detected