Skip to content

Commit

Permalink
Fix matrix-org#1677 and change unique on local_media_repository_thumb…
Browse files Browse the repository at this point in the history
…nails and remote_media_cache_thumbnails
  • Loading branch information
jkolo committed Jan 16, 2017
1 parent 9a8ae6f commit d263a32
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def _generate_thumbnail(self, input_path, t_path, t_width, t_height,
if t_method == "crop":
t_len = thumbnailer.crop(t_path, t_width, t_height, t_type)
elif t_method == "scale":
t_width, t_height = thumbnailer.aspect(t_width, t_height)
t_width = min(m_width, t_width)
t_height = min(m_height, t_height)
t_len = thumbnailer.scale(t_path, t_width, t_height, t_type)
else:
t_len = None
Expand Down
25 changes: 25 additions & 0 deletions synapse/storage/schema/delta/40/thumbnails_index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright 2016 OpenMarket Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

CREATE TABLE local_media_repository_thumbnails2 ( media_id TEXT, thumbnail_width INTEGER, thumbnail_height INTEGER, thumbnail_type TEXT, thumbnail_method TEXT, thumbnail_length INTEGER, UNIQUE ( media_id, thumbnail_width, thumbnail_height, thumbnail_type, thumbnail_method ) );
INSERT INTO local_media_repository_thumbnails2 SELECT * FROM local_media_repository_thumbnails;
DROP TABLE local_media_repository_thumbnails;
ALTER TABLE local_media_repository_thumbnails2 RENAME TO local_media_repository_thumbnails;
CREATE INDEX local_media_repository_thumbnails_media_id ON local_media_repository_thumbnails (media_id);

CREATE TABLE remote_media_cache_thumbnails2 ( media_origin TEXT, media_id TEXT, thumbnail_width INTEGER, thumbnail_height INTEGER, thumbnail_method TEXT, thumbnail_type TEXT, thumbnail_length INTEGER, filesystem_id TEXT, UNIQUE ( media_origin, media_id, thumbnail_width, thumbnail_height, thumbnail_type, thumbnail_method ) );
INSERT INTO remote_media_cache_thumbnails2 SELECT * FROM remote_media_cache_thumbnails;
DROP TABLE remote_media_cache_thumbnails;
ALTER TABLE remote_media_cache_thumbnails2 RENAME TO remote_media_cache_thumbnails;

0 comments on commit d263a32

Please sign in to comment.