watchtower: refactor getClientSession helper funcs

Small refactor to some of the tower client db helper functions in order
to simplify upcoming commits.
This commit is contained in:
Elle Mouton 2022-09-30 10:47:10 +02:00
parent 707546e2f0
commit 3ac3b6a90d
No known key found for this signature in database
GPG key ID: D7D916376026F177

View file

@ -1174,14 +1174,17 @@ func getClientSession(sessions, towers kvdb.RBucket,
return nil, err
}
// Can't fail because client session body has already been read.
sessionBkt := sessions.NestedReadBucket(idBytes)
// Fetch the committed updates for this session.
commitedUpdates, err := getClientSessionCommits(sessions, idBytes)
commitedUpdates, err := getClientSessionCommits(sessionBkt)
if err != nil {
return nil, err
}
// Fetch the acked updates for this session.
ackedUpdates, err := getClientSessionAcks(sessions, idBytes)
ackedUpdates, err := getClientSessionAcks(sessionBkt)
if err != nil {
return nil, err
}
@ -1195,11 +1198,8 @@ func getClientSession(sessions, towers kvdb.RBucket,
// getClientSessionCommits retrieves all committed updates for the session
// identified by the serialized session id.
func getClientSessionCommits(sessions kvdb.RBucket,
idBytes []byte) ([]CommittedUpdate, error) {
// Can't fail because client session body has already been read.
sessionBkt := sessions.NestedReadBucket(idBytes)
func getClientSessionCommits(sessionBkt kvdb.RBucket) ([]CommittedUpdate,
error) {
// Initialize commitedUpdates so that we can return an initialized map
// if no committed updates exist.
@ -1231,11 +1231,8 @@ func getClientSessionCommits(sessions kvdb.RBucket,
// getClientSessionAcks retrieves all acked updates for the session identified
// by the serialized session id.
func getClientSessionAcks(sessions kvdb.RBucket,
idBytes []byte) (map[uint16]BackupID, error) {
// Can't fail because client session body has already been read.
sessionBkt := sessions.NestedReadBucket(idBytes)
func getClientSessionAcks(sessionBkt kvdb.RBucket) (map[uint16]BackupID,
error) {
// Initialize ackedUpdates so that we can return an initialized map if
// no acked updates exist.