Fix info updates

This commit is contained in:
Zoe Roux 2024-08-05 23:11:00 +02:00
parent 6a431a5bb4
commit 14ec227266

View File

@ -210,33 +210,27 @@ func (s *MetadataService) storeFreshMetadata(path string, sha string) (*MediaInf
} }
tx, err := s.database.Begin() tx, err := s.database.Begin()
// TODO: return versions values on update
_, err = tx.Exec(` _, err = tx.Exec(`
do language plpgsql
$$
begin
insert into info(sha, path, extension, mime_codec, size, duration, container, insert into info(sha, path, extension, mime_codec, size, duration, container,
fonts, ver_info, ver_extract, ver_thumbs, ver_keyframes) fonts, ver_info, ver_extract, ver_thumbs, ver_keyframes)
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12); values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
return; on conflict (path) do update set
exception when unique_violation then sha = excluded.sha,
update info set path = excluded.path,
sha = $1, extension = excluded.extension,
path = $2, mime_codec = excluded.mime_codec,
extension = $3, size = excluded.size,
mime_codec = $4, duration = excluded.duration,
size = $5, container = excluded.container,
duration = $6, fonts = excluded.fonts,
container = $7, ver_info = excluded.ver_info
fonts = $8,
ver_info = $9
where sha = $1 or path = $2;
end;
$$;
`, `,
// on conflict do not update versions of extract/thumbs/keyframes // on conflict do not update versions of extract/thumbs/keyframes
ret.Sha, ret.Path, ret.Extension, ret.MimeCodec, ret.Size, ret.Duration, ret.Container, ret.Sha, ret.Path, ret.Extension, ret.MimeCodec, ret.Size, ret.Duration, ret.Container,
pq.Array(ret.Fonts), ret.Versions.Info, ret.Versions.Extract, ret.Versions.Thumbs, ret.Versions.Keyframes, pq.Array(ret.Fonts), ret.Versions.Info, ret.Versions.Extract, ret.Versions.Thumbs, ret.Versions.Keyframes,
) )
fmt.Printf("err: %v", err)
for _, v := range ret.Videos { for _, v := range ret.Videos {
tx.Exec( tx.Exec(
`insert into videos(sha, idx, title, language, codec, mime_codec, width, height, bitrate) `insert into videos(sha, idx, title, language, codec, mime_codec, width, height, bitrate)