Repository: syncthing/syncthing
File: internal/db/interface.go (Go)

Code before:
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

package db

import (
	"iter"
	"time"

	"github.com/syncthing/syncthing/lib/config"
	"github.com/syncthing/syncthing/lib/protocol"
	"github.com/thejerf/suture/v4"
)

type DBService interface {
	suture.Service

	// Starts maintenance asynchronously, if not already running
	// Returns a channel that will receive the result when the requested maintenance finishes
	StartMaintenance() <-chan error

	// Returns the last time database maintenance completed
	// This will return time zero when database maintenance has never completed successfully.
	LastMaintenanceTime() (lastMaint time.Time)
}

type DB interface {
	// Create a service that performs database maintenance periodically (no
	// more often than the requested interval)
	Service(maintenanceInterval time.Duration) DBService

	// Basics
	Update(folder string, device protocol.DeviceID, fs []protocol.FileInfo) error
	Close() error

	// Single files
	GetDeviceFile(folder string, device protocol.DeviceID, file string) (protocol.FileInfo, bool, error)
	GetGlobalAvailability(folder, file string) ([]protocol.DeviceID, error)
	GetGlobalFile(folder string, file string) (protocol.FileInfo, bool, error)

	// File iterators
	//
	// n.b. there is a slight inconsistency in the return types where some
	// return a FileInfo iterator and some a FileMetadata iterator. The
	// latter is more lightweight, and the discrepancy depends on how the
	// functions tend to be used. We can introduce more variations as
	// required.
	AllGlobalFiles(folder string) (iter.Seq[FileMetadata], func() error)
	AllGlobalFilesPrefix(folder string, prefix string) (iter.Seq[FileMetadata], func() error)

Review comment (suggestion):
```suggestion
	LastMaintenanceTime() time.Time
```

Code after:
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

package db

import (
	"iter"
	"time"

	"github.com/syncthing/syncthing/lib/config"
	"github.com/syncthing/syncthing/lib/protocol"
	"github.com/thejerf/suture/v4"
)

type DBService interface {
	suture.Service

	// Starts maintenance asynchronously, if not already running
	// Returns a channel that will receive the result when the requested maintenance finishes
	StartMaintenance() <-chan error

	// Returns the last time database maintenance completed
	// This will return time zero when database maintenance has never completed successfully.
	LastMaintenanceTime() time.Time
}

type DB interface {
	// Create a service that performs database maintenance periodically (no
	// more often than the requested interval)
	Service(maintenanceInterval time.Duration) DBService

	// Basics
	Update(folder string, device protocol.DeviceID, fs []protocol.FileInfo) error
	Close() error

	// Single files
	GetDeviceFile(folder string, device protocol.DeviceID, file string) (protocol.FileInfo, bool, error)
	GetGlobalAvailability(folder, file string) ([]protocol.DeviceID, error)
	GetGlobalFile(folder string, file string) (protocol.FileInfo, bool, error)

	// File iterators
	//
	// n.b. there is a slight inconsistency in the return types where some
	// return a FileInfo iterator and some a FileMetadata iterator. The
	// latter is more lightweight, and the discrepancy depends on how the
	// functions tend to be used. We can introduce more variations as
	// required.
	AllGlobalFiles(folder string) (iter.Seq[FileMetadata], func() error)
	AllGlobalFilesPrefix(folder string, prefix string) (iter.Seq[FileMetadata], func() error)