Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-media-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
matrix-media-repo
Commits
d1a24abb
Commit
d1a24abb
authored
1 year ago
by
Travis Ralston
Browse files
Options
Downloads
Patches
Plain Diff
Discard thumbnails that we ultimately have records for after generation
For
https://github.com/turt2live/matrix-media-repo/issues/459
parent
8c0285a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pipelines/_steps/thumbnails/generate.go
+22
-1
22 additions, 1 deletion
pipelines/_steps/thumbnails/generate.go
with
22 additions
and
1 deletion
pipelines/_steps/thumbnails/generate.go
+
22
−
1
View file @
d1a24abb
...
...
@@ -70,6 +70,27 @@ func Generate(ctx rcontext.RequestContext, mediaRecord *database.DbMedia, width
// At this point, res.i is our thumbnail
// Quickly check to see if we already have a database record for this thumbnail. We do this because predicting
// what the thumbnailer will generate is non-trivial, but it might generate a conflicting thumbnail (particularly
// when `defaultAnimated` is `true`.
db
:=
database
.
GetInstance
()
.
Thumbnails
.
Prepare
(
ctx
)
if
res
.
i
.
Animated
!=
animated
{
// this is the only thing that could have changed during generation
existingRecord
,
err
:=
db
.
GetByParams
(
mediaRecord
.
Origin
,
mediaRecord
.
MediaId
,
width
,
height
,
method
,
res
.
i
.
Animated
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
if
existingRecord
!=
nil
{
ctx
.
Log
.
Debug
(
"Found existing record for parameters - discarding generated thumbnail"
)
defer
res
.
i
.
Reader
.
Close
()
rsc
,
err
:=
download
.
OpenStream
(
ctx
,
existingRecord
.
Locatable
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
return
existingRecord
,
rsc
,
nil
}
}
// We don't have an existing record. Store the stream and insert a record.
thumbMediaRecord
,
thumbStream
,
err
:=
datastore_op
.
PutAndReturnStream
(
ctx
,
ctx
.
Request
.
Host
,
""
,
res
.
i
.
Reader
,
res
.
i
.
ContentType
,
""
,
datastores
.
ThumbnailsKind
)
if
err
!=
nil
{
return
nil
,
nil
,
err
...
...
@@ -92,7 +113,7 @@ func Generate(ctx rcontext.RequestContext, mediaRecord *database.DbMedia, width
Location
:
thumbMediaRecord
.
Location
,
},
}
err
=
d
atabase
.
GetInstance
()
.
Thumbnails
.
Prepare
(
ctx
)
.
Insert
(
newRecord
)
err
=
d
b
.
Insert
(
newRecord
)
if
err
!=
nil
{
defer
thumbStream
.
Close
()
return
nil
,
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment