Repository: syncthing/syncthing
File: lib/model/model.go (Go)

Code before:
	case from.Paused:
		infoMsg = "Unpaused"
		errMsg = "unpausing"
	default:
		infoMsg = "Restarted"
		errMsg = "restarting"
	}

	err := fmt.Errorf("%v folder %v", errMsg, to.Description())
	m.stopFolder(from, err)
	// Need to send CC change to both from and to devices.
	m.closeConns(to.DeviceIDs(), err)

	m.fmut.Lock()
	defer m.fmut.Unlock()

	// Cache the (maybe) existing fset before it's removed by cleanupFolderLocked
	fset := m.folderFiles[to.ID]

	m.cleanupFolderLocked(from)
	if !to.Paused {
		if fset == nil {
			// Create a new fset. Might take a while and we do it under
			// locking, but it's unsafe to create fset:s concurrently so
			// that's the price we pay.
			fset = db.NewFileSet(to.ID, to.Filesystem(), m.db)
		}
		m.addAndStartFolderLocked(to, fset, cacheIgnoredFiles)
	}
	l.Infof("%v folder %v (%v)", infoMsg, to.Description(), to.Type)
}

func (m *model) newFolder(cfg config.FolderConfiguration, cacheIgnoredFiles bool) {
	// Creating the fileset can take a long time (metadata calculation) so
	// we do it outside of the lock.
	fset := db.NewFileSet(cfg.ID, cfg.Filesystem(), m.db)

	// Close connections to affected devices
	m.closeConns(cfg.DeviceIDs(), fmt.Errorf("started folder %v", cfg.Description()))

	m.fmut.Lock()
	defer m.fmut.Unlock()
	m.addAndStartFolderLocked(cfg, fset, cacheIgnoredFiles)
}

func (m *model) UsageReportingStats(report *contract.Report, version int, preview bool) {
	if version >= 3 {
		// Block stats
		blockStatsMut.Lock()
		for k, v := range blockStats {
			switch k {

Review comment (suggestion):
Actually we could maybe release `fmut` for the duration since we have the restart lock, and are guaranteed that only CommitConfiguration could run at any given time ... maybe

Code after:
		errMsg = "pausing"
	case from.Paused:
		infoMsg = "Unpaused"
		errMsg = "unpausing"
	default:
		infoMsg = "Restarted"
		errMsg = "restarting"
	}

	err := fmt.Errorf("%v folder %v", errMsg, to.Description())
	m.stopFolder(from, err)
	// Need to send CC change to both from and to devices.
	m.closeConns(to.DeviceIDs(), err)

	m.fmut.Lock()
	defer m.fmut.Unlock()

	// Cache the (maybe) existing fset before it's removed by cleanupFolderLocked
	fset := m.folderFiles[folder]

	m.cleanupFolderLocked(from)
	if !to.Paused {
		if fset == nil {
			// Create a new fset. Might take a while and we do it under
			// locking, but it's unsafe to create fset:s concurrently so
			// that's the price we pay.
			fset = db.NewFileSet(folder, to.Filesystem(), m.db)
		}
		m.addAndStartFolderLocked(to, fset, cacheIgnoredFiles)
	}
	l.Infof("%v folder %v (%v)", infoMsg, to.Description(), to.Type)
}

func (m *model) newFolder(cfg config.FolderConfiguration, cacheIgnoredFiles bool) {
	// Creating the fileset can take a long time (metadata calculation) so
	// we do it outside of the lock.
	fset := db.NewFileSet(cfg.ID, cfg.Filesystem(), m.db)

	// Close connections to affected devices
	m.closeConns(cfg.DeviceIDs(), fmt.Errorf("started folder %v", cfg.Description()))

	m.fmut.Lock()
	defer m.fmut.Unlock()
	m.addAndStartFolderLocked(cfg, fset, cacheIgnoredFiles)
}

func (m *model) UsageReportingStats(report *contract.Report, version int, preview bool) {
	if version >= 3 {
		// Block stats
		blockStatsMut.Lock()
		for k, v := range blockStats {