Skip to content

Commit

Permalink
[chore] cleanup storage implementation, no need for multiple interfac…
Browse files Browse the repository at this point in the history
…e types (#1131)

Signed-off-by: kim <grufwub@gmail.com>

Signed-off-by: kim <grufwub@gmail.com>
  • Loading branch information
NyaaaWhatsUpDoc committed Nov 24, 2022
1 parent c9d893f commit fcb9c0b
Show file tree
Hide file tree
Showing 35 changed files with 129 additions and 178 deletions.
2 changes: 1 addition & 1 deletion cmd/gotosocial/action/testrig/testrig.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
dbService := testrig.NewTestDB()
testrig.StandardDBSetup(dbService, nil)
router := testrig.NewTestRouter(dbService)
var storageBackend storage.Driver
var storageBackend *storage.Driver
if os.Getenv("GTS_STORAGE_BACKEND") == "s3" {
storageBackend = testrig.NewS3Storage()
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type AccountStandardTestSuite struct {
// standard suite interfaces
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
federator federation.Federator
processor processing.Processor
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type AdminStandardTestSuite struct {
// standard suite interfaces
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
federator federation.Federator
processor processing.Processor
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
type AuthStandardTestSuite struct {
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
federator federation.Federator
processor processing.Processor
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/fileserver/servefile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type ServeFileTestSuite struct {
// standard suite interfaces
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
federator federation.Federator
tc typeutils.TypeConverter
processor processing.Processor
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/followrequest/followrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
type FollowRequestStandardTestSuite struct {
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
federator federation.Federator
processor processing.Processor
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/instance/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type InstanceStandardTestSuite struct {
// standard suite interfaces
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
federator federation.Federator
processor processing.Processor
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/media/mediacreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type MediaCreateTestSuite struct {
// standard suite interfaces
suite.Suite
db db.DB
storage *storage.Local
storage *storage.Driver
mediaManager media.Manager
federator federation.Federator
tc typeutils.TypeConverter
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/media/mediaupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type MediaUpdateTestSuite struct {
// standard suite interfaces
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
federator federation.Federator
tc typeutils.TypeConverter
mediaManager media.Manager
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type StatusStandardTestSuite struct {
federator federation.Federator
emailSender email.Sender
processor processing.Processor
storage storage.Driver
storage *storage.Driver

// standard suite models
testTokens map[string]*gtsmodel.Token
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type UserStandardTestSuite struct {
federator federation.Federator
emailSender email.Sender
processor processing.Processor
storage storage.Driver
storage *storage.Driver

testTokens map[string]*gtsmodel.Token
testClients map[string]*gtsmodel.Client
Expand Down
2 changes: 1 addition & 1 deletion internal/api/s2s/emoji/emojiget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type EmojiGetTestSuite struct {
federator federation.Federator
emailSender email.Sender
processor processing.Processor
storage storage.Driver
storage *storage.Driver
oauthServer oauth.Server
securityModule *security.Module

Expand Down
2 changes: 1 addition & 1 deletion internal/api/s2s/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type UserStandardTestSuite struct {
federator federation.Federator
emailSender email.Sender
processor processing.Processor
storage storage.Driver
storage *storage.Driver
oauthServer oauth.Server
securityModule *security.Module

Expand Down
2 changes: 1 addition & 1 deletion internal/api/s2s/webfinger/webfinger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type WebfingerStandardTestSuite struct {
federator federation.Federator
emailSender email.Sender
processor processing.Processor
storage storage.Driver
storage *storage.Driver
oauthServer oauth.Server
securityModule *security.Module

Expand Down
2 changes: 1 addition & 1 deletion internal/federation/dereferencing/dereferencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
type DereferencerStandardTestSuite struct {
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver

testRemoteStatuses map[string]vocab.ActivityStreamsNote
testRemotePeople map[string]vocab.ActivityStreamsPerson
Expand Down
2 changes: 1 addition & 1 deletion internal/federation/federator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
type FederatorStandardTestSuite struct {
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
tc typeutils.TypeConverter
testAccounts map[string]*gtsmodel.Account
testStatuses map[string]*gtsmodel.Status
Expand Down
4 changes: 2 additions & 2 deletions internal/media/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type Manager interface {

type manager struct {
db db.DB
storage storage.Driver
storage *storage.Driver
emojiWorker *concurrency.WorkerPool[*ProcessingEmoji]
mediaWorker *concurrency.WorkerPool[*ProcessingMedia]
stopCronJobs func() error
Expand All @@ -112,7 +112,7 @@ type manager struct {
// a limited number of media will be processed in parallel. The numbers of workers
// is determined from the $GOMAXPROCS environment variable (usually no. CPU cores).
// See internal/concurrency.NewWorkerPool() documentation for further information.
func NewManager(database db.DB, storage storage.Driver) (Manager, error) {
func NewManager(database db.DB, storage *storage.Driver) (Manager, error) {
m := &manager{
db: database,
storage: storage,
Expand Down
13 changes: 9 additions & 4 deletions internal/media/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,14 +927,19 @@ func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingWithDiskStorage() {
temp := fmt.Sprintf("%s/gotosocial-test", os.TempDir())
defer os.RemoveAll(temp)

diskStorage, err := kv.OpenDisk(temp, &storage.DiskConfig{
disk, err := storage.OpenDisk(temp, &storage.DiskConfig{
LockFile: path.Join(temp, "store.lock"),
})
if err != nil {
panic(err)
}

diskManager, err := media.NewManager(suite.db, &gtsstorage.Local{KVStore: diskStorage})
storage := &gtsstorage.Driver{
KVStore: kv.New(disk),
Storage: disk,
}

diskManager, err := media.NewManager(suite.db, storage)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -974,7 +979,7 @@ func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingWithDiskStorage() {
suite.NotNil(dbAttachment)

// make sure the processed file is in storage
processedFullBytes, err := diskStorage.Get(ctx, attachment.File.Path)
processedFullBytes, err := storage.Get(ctx, attachment.File.Path)
suite.NoError(err)
suite.NotEmpty(processedFullBytes)

Expand All @@ -987,7 +992,7 @@ func (suite *ManagerTestSuite) TestSimpleJpegProcessBlockingWithDiskStorage() {
suite.Equal(processedFullBytesExpected, processedFullBytes)

// now do the same for the thumbnail and make sure it's what we expected
processedThumbnailBytes, err := diskStorage.Get(ctx, attachment.Thumbnail.Path)
processedThumbnailBytes, err := storage.Get(ctx, attachment.Thumbnail.Path)
suite.NoError(err)
suite.NotEmpty(processedThumbnailBytes)

Expand Down
2 changes: 1 addition & 1 deletion internal/media/media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type MediaStandardTestSuite struct {
suite.Suite

db db.DB
storage storage.Driver
storage *storage.Driver
manager media.Manager
testAttachments map[string]*gtsmodel.MediaAttachment
testAccounts map[string]*gtsmodel.Account
Expand Down
2 changes: 1 addition & 1 deletion internal/media/processingemoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ProcessingEmoji struct {
*/

database db.DB
storage storage.Driver
storage *storage.Driver

err error // error created during processing, if any

Expand Down
2 changes: 1 addition & 1 deletion internal/media/processingmedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type ProcessingMedia struct {
*/

database db.DB
storage storage.Driver
storage *storage.Driver

err error // error created during processing, if any

Expand Down
2 changes: 1 addition & 1 deletion internal/media/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (r *lengthReader) Read(b []byte) (int, error) {
// putStream either puts a file with a known fileSize into storage directly, and returns the
// fileSize unchanged, or it wraps the reader with a lengthReader and returns the discovered
// fileSize.
func putStream(ctx context.Context, storage storage.Driver, key string, r io.Reader, fileSize int64) (int64, error) {
func putStream(ctx context.Context, storage *storage.Driver, key string, r io.Reader, fileSize int64) (int64, error) {
if fileSize > 0 {
return fileSize, storage.PutStream(ctx, key, r)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/processing/account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type AccountStandardTestSuite struct {
suite.Suite
db db.DB
tc typeutils.TypeConverter
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
oauthServer oauth.Server
fromClientAPIChan chan messages.FromClientAPI
Expand Down
4 changes: 2 additions & 2 deletions internal/processing/media/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ type processor struct {
tc typeutils.TypeConverter
mediaManager media.Manager
transportController transport.Controller
storage storage.Driver
storage *storage.Driver
db db.DB
}

// New returns a new media processor.
func New(db db.DB, tc typeutils.TypeConverter, mediaManager media.Manager, transportController transport.Controller, storage storage.Driver) Processor {
func New(db db.DB, tc typeutils.TypeConverter, mediaManager media.Manager, transportController transport.Controller, storage *storage.Driver) Processor {
return &processor{
tc: tc,
mediaManager: mediaManager,
Expand Down
2 changes: 1 addition & 1 deletion internal/processing/media/media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type MediaStandardTestSuite struct {
suite.Suite
db db.DB
tc typeutils.TypeConverter
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
transportController transport.Controller

Expand Down
4 changes: 2 additions & 2 deletions internal/processing/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ type processor struct {
tc typeutils.TypeConverter
oauthServer oauth.Server
mediaManager media.Manager
storage storage.Driver
storage *storage.Driver
statusTimelines timeline.Manager
db db.DB
filter visibility.Filter
Expand All @@ -297,7 +297,7 @@ func NewProcessor(
federator federation.Federator,
oauthServer oauth.Server,
mediaManager media.Manager,
storage storage.Driver,
storage *storage.Driver,
db db.DB,
emailSender email.Sender,
clientWorker *concurrency.WorkerPool[messages.FromClientAPI],
Expand Down
2 changes: 1 addition & 1 deletion internal/processing/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ProcessingStandardTestSuite struct {
// standard suite interfaces
suite.Suite
db db.DB
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
typeconverter typeutils.TypeConverter
httpClient *testrig.MockHTTPClient
Expand Down
2 changes: 1 addition & 1 deletion internal/processing/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type StatusStandardTestSuite struct {
db db.DB
typeConverter typeutils.TypeConverter
tc transport.Controller
storage storage.Driver
storage *storage.Driver
mediaManager media.Manager
federator federation.Federator
clientWorker *concurrency.WorkerPool[messages.FromClientAPI]
Expand Down
34 changes: 0 additions & 34 deletions internal/storage/local.go

This file was deleted.

50 changes: 0 additions & 50 deletions internal/storage/s3.go

This file was deleted.

0 comments on commit fcb9c0b

Please sign in to comment.