code: func (deallocator *Deallocator) processNetwork(ctx context.Context, tx store.Tx, network *api.Network, ignoreServiceID *string) (updated bool, err error) {
  	if !network.PendingDelete {
  		return
  	}
  
  	updateFunc := func(t store.Tx) error {
  		services, err := store.FindServices(t, store.ByReferencedNetworkID(network.ID))
  
  		if err != nil {
  			log.G(ctx).WithError(err).Errorf("could not fetch services using network ID %v", network.ID)
  			return err
  		}
  
  		noMoreServices := len(services) == 0 ||
  			len(services) == 1 && ignoreServiceID != nil && services[0].ID == *ignoreServiceID
  
  		if noMoreServices {
  			return store.DeleteNetwork(t, network.ID)
  		}
  		return nil
  	}
  
  	if tx == nil {
  		err = deallocator.store.Update(updateFunc)
  	} else {
  		err = updateFunc(tx)
  	}
  
  	if err != nil {
  		log.G(ctx).WithError(err).Errorf("DB error when deallocating network ID %v", network.ID)
  	}
  	return
  }
docs: // proceeds to deallocate a network if it's pending deletion and there no
  // longer are any services using it
  // actually deletes the network if it's marked for deletion and no services are
  // using it any more (or the only one using it has ID `ignoreServiceID`, if not
  // nil - this comes in handy when there's been an error deleting a service)
  // This function can be called either when deallocating a whole service, or
  // because there was an `EventUpdateNetwork` event - in the former case, the
  // transaction will be that of the service deallocation, in the latter it will be nil