'juju list-models' loads each Model object 3 times

Bug #1732384 reported by John A Meinel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Fix Released
High
John A Meinel

Bug Description

Tracking through the code, we have a couple bugs.

List models does this:

    for _, modelUUID := range modelUUIDs {
  st, release, err := m.state.GetBackend(modelUUID)

^- GetBackend is a modelManagerStateShim which requires both a 'state' and an 'model' so it does:
 otherState, release, err := st.pool.Get(modelUUID)
...
 otherModel, err := otherState.Model()

...
 return modelManagerStateShim{otherState, otherModel, st.pool}, release, nil
that is the first load. AFAICT ListModels does nothing with this object, but we still do all the work to read it from the DB.

  if err != nil {
   // This model could have been removed.
   if errors.IsNotFound(err) {
    continue
   }
   return result, errors.Trace(err)
  }
  defer release()

  model, err := st.Model()
  if err != nil {
   return result, errors.Trace(err)
  }
^- our first use to load it directly

  var lastConn *time.Time
  userLastConn, err := model.LastModelConnection(userTag)
  if err != nil {
   if !state.IsNeverConnectedError(err) {
    return result, errors.Trace(err)
   }
  } else {
   lastConn = &userLastConn
  }

  model, err = st.Model()
  if err != nil {
   return result, errors.Trace(err)
  }
^- we then load it one more time, just to be sure.

  result.UserModels = append(result.UserModels, params.UserModel{
   Model: params.Model{
    Name: model.Name(),
    UUID: model.UUID(),
    OwnerTag: model.Owner().String(),
   },
   LastConnection: lastConn,
  })
 }

There might be a different function we could use:

func (st modelManagerStateShim) GetModel(modelUUID string) (Model, func() bool, error) {
 model, release, err := st.pool.GetModel(modelUUID)
...
 return modelShim{model}, release, nil
}

But the above is calling st.Model() and not st.GetModel.

Tim Penhey (thumper)
Changed in juju:
milestone: 2.3-rc1 → 2.3.1
Revision history for this message
John A Meinel (jameinel) wrote :
Changed in juju:
milestone: 2.3.1 → 2.3-rc1
milestone: 2.3-rc1 → 2.3-rc2
Ian Booth (wallyworld)
Changed in juju:
status: In Progress → Fix Committed
Changed in juju:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.