Skip to content

Commit

Permalink
Drop blurhashes support
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Sep 5, 2023
1 parent b9ab418 commit 9286c1d
Show file tree
Hide file tree
Showing 14 changed files with 7 additions and 223 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ path/server, for example, then you can simply update the path in the config for

* IPFS support has been removed due to maintenance burden.
* Exports initiated through the admin API no longer support `?include_data=false`. Exports will always contain data.
* Server-side blurhash calculation has been removed. Clients and bridges already calculate blurhashes locally where applicable.

### Changed

Expand Down
10 changes: 1 addition & 9 deletions api/r0/upload_async.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/turt2live/matrix-media-repo/api/_routers"
"github.com/turt2live/matrix-media-repo/common"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/database"
"github.com/turt2live/matrix-media-repo/pipelines/pipeline_upload"
)

Expand Down Expand Up @@ -46,7 +45,7 @@ func UploadMediaAsync(r *http.Request, rctx rcontext.RequestContext, user _apime
}

// Actually upload
media, err := pipeline_upload.ExecutePut(rctx, server, mediaId, r.Body, contentType, filename, user.UserId)
_, err := pipeline_upload.ExecutePut(rctx, server, mediaId, r.Body, contentType, filename, user.UserId)
if err != nil {
if errors.Is(err, common.ErrQuotaExceeded) {
return _responses.QuotaExceeded()
Expand Down Expand Up @@ -74,14 +73,7 @@ func UploadMediaAsync(r *http.Request, rctx rcontext.RequestContext, user _apime
return _responses.InternalServerError("Unexpected Error")
}

blurhash, err := database.GetInstance().Blurhashes.Prepare(rctx).Get(media.Sha256Hash)
if err != nil {
rctx.Log.Warn("Unexpected error getting media's blurhash from DB: ", err)
sentry.CaptureException(err)
}

return &MediaUploadedResponse{
//ContentUri: util.MxcUri(media.Origin, media.MediaId), // This endpoint doesn't return a URI
Blurhash: blurhash,
}
}
9 changes: 0 additions & 9 deletions api/r0/upload_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import (
"github.com/turt2live/matrix-media-repo/api/_responses"
"github.com/turt2live/matrix-media-repo/common"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/database"
"github.com/turt2live/matrix-media-repo/datastores"
"github.com/turt2live/matrix-media-repo/pipelines/pipeline_upload"
"github.com/turt2live/matrix-media-repo/util"
)

type MediaUploadedResponse struct {
ContentUri string `json:"content_uri,omitempty"`
Blurhash string `json:"xyz.amorgan.blurhash,omitempty"`
}

func UploadMediaSync(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
Expand Down Expand Up @@ -51,15 +49,8 @@ func UploadMediaSync(r *http.Request, rctx rcontext.RequestContext, user _apimet
return _responses.InternalServerError("Unexpected Error")
}

blurhash, err := database.GetInstance().Blurhashes.Prepare(rctx).Get(media.Sha256Hash)
if err != nil {
rctx.Log.Warn("Unexpected error getting media's blurhash from DB: ", err)
sentry.CaptureException(err)
}

return &MediaUploadedResponse{
ContentUri: util.MxcUri(media.Origin, media.MediaId),
Blurhash: blurhash,
}
}

Expand Down
8 changes: 0 additions & 8 deletions api/unstable/local_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/turt2live/matrix-media-repo/api/r0"
"github.com/turt2live/matrix-media-repo/common"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/database"
"github.com/turt2live/matrix-media-repo/datastores"
"github.com/turt2live/matrix-media-repo/pipelines/pipeline_download"
"github.com/turt2live/matrix-media-repo/pipelines/pipeline_upload"
Expand Down Expand Up @@ -97,14 +96,7 @@ func LocalCopy(r *http.Request, rctx rcontext.RequestContext, user _apimeta.User
return _responses.InternalServerError("Unexpected Error")
}

blurhash, err := database.GetInstance().Blurhashes.Prepare(rctx).Get(record.Sha256Hash)
if err != nil {
rctx.Log.Warn("Unexpected error getting media's blurhash from DB: ", err)
sentry.CaptureException(err)
}

return &r0.MediaUploadedResponse{
ContentUri: util.MxcUri(record.Origin, record.MediaId),
Blurhash: blurhash,
}
}
11 changes: 1 addition & 10 deletions common/config/conf_min_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ func NewDefaultMinimumRepoConfig() MinimumRepoConfig {
ClientServer: 30,
Federation: 120,
},
Features: FeatureConfig{
MSC2448Blurhash: MSC2448Config{
Enabled: false,
GenerateWidth: 64,
GenerateHeight: 64,
XComponents: 4,
YComponents: 3,
Punch: 1,
},
},
Features: FeatureConfig{},
AccessTokens: AccessTokenConfig{
MaxCacheTimeSeconds: 0,
UseAppservices: false,
Expand Down
10 changes: 0 additions & 10 deletions common/config/models_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ type TimeoutsConfig struct {
}

type FeatureConfig struct {
MSC2448Blurhash MSC2448Config `yaml:"MSC2448"`
}

type MSC2448Config struct {
Enabled bool `yaml:"enabled"`
GenerateWidth int `yaml:"thumbWidth"`
GenerateHeight int `yaml:"thumbHeight"`
XComponents int `yaml:"xComponents"`
YComponents int `yaml:"yComponents"`
Punch int `yaml:"punch"`
}

type AccessTokenConfig struct {
Expand Down
7 changes: 1 addition & 6 deletions common/config/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ func onFileChanged() {
bindPortChange := configNew.General.Port != configNow.General.Port
forwardAddressChange := configNew.General.TrustAnyForward != configNow.General.TrustAnyForward
forwardedHostChange := configNew.General.UseForwardedHost != configNow.General.UseForwardedHost
featureChanged := hasWebFeatureChanged(configNew, configNow)
if bindAddressChange || bindPortChange || forwardAddressChange || forwardedHostChange || featureChanged {
if bindAddressChange || bindPortChange || forwardAddressChange || forwardedHostChange {
logrus.Warn("Webserver configuration changed - remounting")
globals.WebReloadChan <- true
}
Expand Down Expand Up @@ -126,10 +125,6 @@ func onFileChanged() {
}
}

func hasWebFeatureChanged(configNew *MainRepoConfig, configNow *MainRepoConfig) bool {
return configNew.Features.MSC2448Blurhash.Enabled != configNow.Features.MSC2448Blurhash.Enabled
}

func hasRedisShardConfigChanged(configNew *MainRepoConfig, configNow *MainRepoConfig) bool {
oldShards := configNow.Redis.Shards
newShards := configNew.Redis.Shards
Expand Down
17 changes: 1 addition & 16 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -547,22 +547,7 @@ plugins:
# Sections of this config might disappear or be added over time. By default all
# features are disabled in here and must be explicitly enabled to be used.
featureSupport:
# MSC2248 - Blurhash
MSC2448:
# Whether or not this MSC is enabled for use in the media repo
enabled: false

# Thumbnail size in pixels to use to generate the blurhash string
thumbWidth: 64
thumbHeight: 64

# The X and Y components to use. Higher numbers blur less, lower numbers blur more.
xComponents: 4
yComponents: 3

# The amount of contrast to apply when converting a blurhash to an image. Lower values
# make the effect more subtle, larger values make it stronger.
punch: 1
# No unstable features are currently supported.

# Support for redis as a cache mechanism
#
Expand Down
4 changes: 0 additions & 4 deletions database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Database struct {
UserStats *userStatsTableStatements
ReservedMedia *reservedMediaTableStatements
MetadataView *metadataVirtualTableStatements
Blurhashes *blurhashesTableStatements
HeldMedia *heldMediaTableStatements
Thumbnails *thumbnailsTableStatements
LastAccess *lastAccessTableStatements
Expand Down Expand Up @@ -101,9 +100,6 @@ func openDatabase(connectionString string, maxConns int, maxIdleConns int) error
if d.MetadataView, err = prepareMetadataVirtualTables(d.conn); err != nil {
return errors.New("failed to create metadata virtual table accessor: " + err.Error())
}
if d.Blurhashes, err = prepareBlurhashesTables(d.conn); err != nil {
return errors.New("failed to create blurhashes table accessor: " + err.Error())
}
if d.HeldMedia, err = prepareHeldMediaTables(d.conn); err != nil {
return errors.New("failed to create held media table accessor: " + err.Error())
}
Expand Down
63 changes: 0 additions & 63 deletions database/table_blurhashes.go

This file was deleted.

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
)

require (
github.com/bbrks/go-blurhash v1.1.1
github.com/docker/docker v24.0.5+incompatible
github.com/docker/go-connections v0.4.0
github.com/go-redsync/redsync/v4 v4.8.2
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ github.com/alioygur/is v1.0.3/go.mod h1:fmXi78K26iMaOs0fINRVLl1TIPCYcLfOopoZ5+mc
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/bbrks/go-blurhash v1.1.1 h1:uoXOxRPDca9zHYabUTwvS4KnY++KKUbwFo+Yxb8ME4M=
github.com/bbrks/go-blurhash v1.1.1/go.mod h1:lkAsdyXp+EhARcUo85yS2G1o+Sh43I2ebF5togC4bAY=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
Expand Down Expand Up @@ -252,8 +250,6 @@ github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down
69 changes: 0 additions & 69 deletions pipelines/_steps/upload/blurhash_async.go

This file was deleted.

16 changes: 2 additions & 14 deletions pipelines/pipeline_upload/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,11 @@ func Execute(ctx rcontext.RequestContext, origin string, mediaId string, r io.Re
return nil, common.ErrMediaQuarantined
}

// Step 5: Split the buffer to calculate a blurhash & populate cache later
bhR, bhW := io.Pipe()
// Step 5: Split the buffer to populate cache later
cacheR, cacheW := io.Pipe()
allWriters := io.MultiWriter(cacheW, bhW)
allWriters := io.MultiWriter(cacheW)
tee := io.TeeReader(reader, allWriters)

defer func(bhW *io.PipeWriter, err error) {
_ = bhW.CloseWithError(err)
}(bhW, errors.New("failed to finish write"))
defer func(cacheW *io.PipeWriter, err error) {
_ = cacheW.CloseWithError(err)
}(cacheW, errors.New("failed to finish write"))
Expand Down Expand Up @@ -149,9 +145,6 @@ func Execute(ctx rcontext.RequestContext, origin string, mediaId string, r io.Re
}
}

// Step 10: Asynchronously calculate blurhash
bhChan := upload.CalculateBlurhashAsync(ctx, bhR, sizeBytes, sha256hash)

// Step 11: Asynchronously upload to cache
cacheChan := upload.PopulateCacheAsync(ctx, cacheR, sizeBytes, sha256hash)

Expand All @@ -160,17 +153,12 @@ func Execute(ctx rcontext.RequestContext, origin string, mediaId string, r io.Re
if err != nil {
return nil, err
}
if err = bhW.Close(); err != nil {
ctx.Log.Warn("Failed to close writer for blurhash: ", err)
close(bhChan)
}
if err = cacheW.Close(); err != nil {
ctx.Log.Warn("Failed to close writer for cache layer: ", err)
close(cacheChan)
}

// Step 13: Wait for channels
<-bhChan
<-cacheChan

// Step 14: Everything finally looks good - return some stuff
Expand Down

0 comments on commit 9286c1d

Please sign in to comment.