Legend:
- Unmodified
- Added
- Removed
-
trunk/db.go
r263 r267 48 48 Key string 49 49 } 50 51 var ErrNoSuchChannel = fmt.Errorf("soju: no such channel")52 50 53 51 const schema = ` … … 372 370 } 373 371 374 func (db *DB) GetChannel(networkID int64, name string) (*Channel, error) {375 db.lock.RLock()376 defer db.lock.RUnlock()377 378 ch := &Channel{Name: name}379 380 var key *string381 row := db.db.QueryRow("SELECT id, key FROM Channel WHERE network = ? AND name = ?", networkID, name)382 if err := row.Scan(&ch.ID, &key); err == sql.ErrNoRows {383 return nil, ErrNoSuchChannel384 } else if err != nil {385 return nil, err386 }387 ch.Key = fromStringPtr(key)388 return ch, nil389 }390 391 372 func (db *DB) StoreChannel(networkID int64, ch *Channel) error { 392 373 db.lock.Lock() -
trunk/upstream.go
r263 r267 422 422 uc.logger.Printf("connection registered") 423 423 424 channels, err := uc.srv.db.ListChannels(uc.network.ID) 425 if err != nil { 426 uc.logger.Printf("failed to list channels from database: %v", err) 427 break 428 } 429 430 for _, ch := range channels { 424 for _, ch := range uc.network.channels { 431 425 params := []string{ch.Name} 432 426 if ch.Key != "" { -
trunk/user.go
r253 r267 57 57 58 58 conn *upstreamConn 59 channels map[string]*Channel 59 60 history map[string]*networkHistory // indexed by entity 60 61 offlineClients map[string]struct{} // indexed by client name … … 62 63 } 63 64 64 func newNetwork(user *user, record *Network) *network { 65 func newNetwork(user *user, record *Network, channels []Channel) *network { 66 m := make(map[string]*Channel, len(channels)) 67 for _, ch := range channels { 68 m[ch.Name] = &ch 69 } 70 65 71 return &network{ 66 72 Network: *record, 67 73 user: user, 68 74 stopped: make(chan struct{}), 75 channels: m, 69 76 history: make(map[string]*networkHistory), 70 77 offlineClients: make(map[string]struct{}), … … 141 148 142 149 func (net *network) createUpdateChannel(ch *Channel) error { 143 if dbCh, err := net.user.srv.db.GetChannel(net.ID, ch.Name); err == nil { 144 ch.ID = dbCh.ID 145 } else if err != ErrNoSuchChannel { 150 if current, ok := net.channels[ch.Name]; ok { 151 ch.ID = current.ID // update channel if it already exists 152 } 153 if err := net.user.srv.db.StoreChannel(net.ID, ch); err != nil { 146 154 return err 147 155 } 148 return net.user.srv.db.StoreChannel(net.ID, ch) 156 net.channels[ch.Name] = ch 157 return nil 149 158 } 150 159 151 160 func (net *network) deleteChannel(name string) error { 152 return net.user.srv.db.DeleteChannel(net.ID, name) 161 if err := net.user.srv.db.DeleteChannel(net.ID, name); err != nil { 162 return err 163 } 164 delete(net.channels, name) 165 return nil 153 166 } 154 167 … … 222 235 223 236 for _, record := range networks { 224 network := newNetwork(u, &record) 237 channels, err := u.srv.db.ListChannels(record.ID) 238 if err != nil { 239 u.srv.Logger.Printf("failed to list channels for user %q, network %q: %v", u.Username, record.GetName(), err) 240 } 241 242 network := newNetwork(u, &record, channels) 225 243 u.networks = append(u.networks, network) 226 244 … … 354 372 } 355 373 356 network := newNetwork(u, net )374 network := newNetwork(u, net, nil) 357 375 err := u.srv.db.StoreNetwork(u.Username, &network.Network) 358 376 if err != nil {
Note:
See TracChangeset
for help on using the changeset viewer.