Commit Graph

9062 Commits

Author SHA1 Message Date
evazion
3fcecd59a8 Add derailed_benchmarks gem. 2021-12-16 00:53:48 -06:00
evazion
a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00
evazion
fbcf98db96 seo: prevent crawling comment, show_seq links.
* Mark /comments/:id links in comment timestamps as nofollow to prevent
  Googlebot from crawling these links.
* Mark /posts/:id/show_seq links as disallowed in robots.txt to prevent
  Googlebot from crawling forward/back links on posts.
2021-12-13 05:24:07 -06:00
evazion
c0610cb809 posts: reduce sidebar width on laptops/tablets.
This allows fitting one more medium-size thumbnail per row on
laptop and tablet size screens.
2021-12-13 05:24:05 -06:00
evazion
0997f5595e posts: increase default thumbnail size.
* Increase the default thumbnail size from small (150x150) to medium (180x180).
* Change the mobile layout to use three posts per row instead of two for small thumbnails.

Parent/child posts are still 150x150 to avoid taking up even more space above posts.
2021-12-13 05:23:38 -06:00
evazion
e04892fb38 posts: use 180x180 thumbnails in place of 150x150 thumbnails.
For small thumbnails, use 180x180 thumbnails scaled down to 150x150.
This is so we can get rid of 150x150 images and just use 180x180 for
both small and medium size thumbnails.

Also fix RSS feeds, XML sitemaps, and Discord embeds to use 360x360
thumbnails instead of 150x150 thumbnails.
2021-12-13 05:23:38 -06:00
evazion
9eed21ef14 posts: bottom align thumbnails; prevent thumbnail reflow.
* Bottom-align thumbnails on desktop. This is so that vote buttons line
  up beneath thumbnails. Also so that pool titles line up on the pool
  gallery page. This is desktop only because it tends to leave large
  gaps above thumbnails on mobile.

* Make thumbnails fixed-height so that the layout doesn't shift as
  thumbnails are loaded.
2021-12-13 05:23:00 -06:00
evazion
487b51efe4 related tags: fix related tag section being hidden.
Fix the related tags section being completely hidden when it was
collapsed. The `.hidden` CSS class that was used by related tags
conflicted with the `.hidden` utility class added in 8841de68ac.
2021-12-10 06:02:46 -06:00
evazion
bf022e858a seo: prevent crawlers from crawling /posts/:id/favorites. 2021-12-10 01:46:01 -06:00
evazion
4021ddb579 Fix N+1 queries problem in /explore/posts/popular.json. 2021-12-10 01:46:01 -06:00
evazion
514c57ce58 api: add rate limit to /explore/posts/popular.json endpoint.
Add a rate limit of 1 request per minute to the /explore/posts/popular.json endpoint.
This is to deal with a particular bot checking this page multiple times
per second.
2021-12-10 01:46:01 -06:00
evazion
36985e9590 api: add rate limit to /posts.atom endpoint.
Add a rate limit of 1 request per 2 seconds to the post RSS feed
endpoint (/posts.atom).

This lets you check your feeds 30 times per minute, or 1800 times per
hour. The previous limit was 10 requests per second.

This is because there are too many bad RSS feed reader bots constantly
checking the same tags over and over again, 24 hours a day, as fast
they can.
2021-12-10 01:46:01 -06:00
evazion
2e9f4dc2f4 controllers: refactor rate limits.
Refactor controllers so that endpoint rate limits are declared locally,
with the endpoint, instead of globally, in a single method in ApplicationController.

This way an endpoint's rate limit is declared in the same file as the
endpoint itself.

This is so we can add fine-grained rate limits for certain GET requests.
Before rate limits were only for non-GET requests.
2021-12-10 01:46:01 -06:00
evazion
52013eac1f posts: use low quality thumbnails when Save-Data header is set.
When the Save-Data HTTP header is present, disable high quality (2x
pixel density) thumbnails. This is normally set when "Data Saver mode"
is enabled on Android, or "Lite mode" is enabled in Chrome.

This setting can also be set using the `save_data` URL param or HTTP
cookie. This is mainly for testing.

The <body> tag has a `current-user-save-data` data attribute that
indicates whether save data mode is on.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Save-Data
https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/save-data/#the_save-data_request_header
https://source.android.com/devices/tech/connect/data-saver
2021-12-09 20:08:27 -06:00
evazion
7dbde7bc14 Fix #4933: Don't allow mass update requests if both the antecedent and consequent are single tags 2021-12-09 18:05:14 -06:00
evazion
00153b9214 html: add cookie data attributes to <body> tag.
* Add `data-cookie-*` attributes to the <body> tag
* Add a `post-preview-show-votes` class to thumbnails.

Ref: https://github.com/danbooru/danbooru/issues/4930#issuecomment-978064810
2021-12-09 16:26:19 -06:00
evazion
7976d12cd0 Fix #4930: "Show scores" setting should be preserved
Make "show scores" setting persistent.

The setting is stored in a `post_preview_show_votes` cookie. This means
it's remembered on a per-device basis, but not on a per-account basis.
This is so users without an account can use the setting, and so you can
use different settings on desktop and mobile.

The `view=score` URL param has been replaced by `show_votes=true`. The
`show_votes` URL param overrides the `post_preview_show_votes` cookie.
2021-12-09 15:47:10 -06:00
evazion
3de93f556e posts: make thumbnail size setting persistent.
Make setting the thumbnail size persistent.

The setting is stored in a `post_preview_size` cookie. This cookie can
be overridden by the `size` URL param, like so:

  https://danbooru.donmai.us/posts?tags=touhou&size=180

The `size` param is mainly for testing different sizes without setting a cookie.
2021-12-09 15:46:08 -06:00
evazion
208b618918 tags: remove tag category locks.
Remove the ability to lock a tag's category. Before a moderator could
lock a tag such that only an admin could change the tag's category.

Nowadays the ability to change a tag's category is based on the tag's
size. Members can change tag categories for tags with up to 50 posts,
and Builders can change categories for tags with up to 1000 posts.
Manually locking tags is not necessary.

We only had a few dozen locked tags, mostly random *_(cosplay) tags or
company name tags. Most of these are holdovers from moderators randomly
locking tags like ten years ago.

The `is_locked` field is still in the database, so it is still returned
by the /tags.json API, even though it is unused.
2021-12-09 13:20:26 -06:00
evazion
a28078fdaa tags: fix tag category permissions in tag edit form.
Fix the tag edit page letting users attempt to change a tag's category,
even when the tag was too large for the user to change. Trying to change
the category would fail, but with a confusing error message.
2021-12-09 13:12:15 -06:00
evazion
674c502cd3 Fix #4937: "Similar Posts" previews have wrong filesize (150 bytes). 2021-12-09 12:56:49 -06:00
evazion
e9bde54890 css: fix aspect ratio for 225, 270 size thumbnails.
When setting max-height, we also have to set width to auto to preserve
the aspect ratio.
2021-12-08 23:44:48 -06:00
evazion
16216070e0 posts: fix tag scripts not working.
If the `size` URL param wasn't present, then `size=null` would be passed
to `/posts/:id.js`, which would fail because `null` wasn't a valid size.

Regression in 8841de68ac.
2021-12-08 23:22:56 -06:00
evazion
908a0bf3e0 posts: show 2 thumbnails per row on mobile instead of 3.
Fix regression in e8f9e3ab2 after adding adjustable thumbnail sizes.
2021-12-08 20:30:13 -06:00
evazion
810df2f19c posts: fix thumbnail css.
Fix thumbnail CSS to not use `width: auto`, because that made the page
reflow. It made thumbnails start out at 0x0 size, then resize to the
actual size only after the image was loaded.
2021-12-08 19:51:24 -06:00
evazion
f02b437085 bigquery: temp disable dumping the posts table.
Dumping the posts table to BigQuery tends to timeout and leave stuck
jobs in the jobs table. Disable it until it can be fixed.
2021-12-08 18:04:14 -06:00
evazion
aafe250220 posts: make tooltips taller and narrower. 2021-12-08 18:02:55 -06:00
evazion
45dbc7582c Update Ruby gems and Yarn packages. 2021-12-08 03:01:54 -06:00
evazion
7e57ae7d3c posts: inline partials in posts/index template.
Make the posts/index template easier to read by putting everything in
one file, instead of splitting it up into a bunch of partials that
aren't used anywhere else.
2021-12-08 03:01:54 -06:00
evazion
c94fdef3b2 foundation: fix fetching artist commentary.
The markup for the description changed from a <div> to a <h2>.
2021-12-08 03:01:54 -06:00
evazion
8669edd93f artists: add mega.nz to artist finder blacklist. 2021-12-07 04:12:52 -06:00
evazion
dab31a3ef0 media assets: fix exception when generating thumbnails for videos/ugoiras. 2021-12-06 19:01:34 -06:00
evazion
c22f7b799b media assets: fix error when generating thumbnails for corrupt files.
Fix an error being raised when trying to generate thumbnails for corrupt
files. If the original image is corrupt, then ignore any errors and let
libvips try to generate a thumbnail as best it can. This will usually
result in an incomplete thumbnail.
2021-12-05 21:46:14 -06:00
evazion
853569701b media assets: fix error when thumbnailing 16-bit images.
Fix an error caused when trying to generate thumbnails for 16-bit
PNG images.
2021-12-05 21:36:20 -06:00
evazion
ad49a10147 media assets: fix bug in thumbnail generation.
Fix thumbnail generation throwing a NoMatchingPatternError.
2021-12-05 19:04:17 -06:00
evazion
396062869a posts: fix thumbnails on comment and modqueue pages.
Fix thumbnails being fit-to-width instead of a fixed size on the
/comments and /modqueue pages, which caused the columns to be misaligned.
2021-12-05 16:39:24 -06:00
evazion
9cb70fa632 posts: add 720x720 thumbnail size.
This is used to provide higher resolution thumbnails for high pixel
density displays, such as phones or laptops. If your screen has a 2x
pixel density ratio, then 360x360 thumbnails will be rendered at 720x720
resolution.

We use WebP here because it's about 15% smaller than the equivalent
JPEG, and because if a device has a high enough pixel density to use
this, then it probably supports WebP.

720x720 thumbnails average about 36kb in size, compared to 20.35kb for
360x360 thumbnails and 7.55kb for 180x180 thumbnails.
2021-12-05 09:19:29 -06:00
evazion
92906f7d39 posts: fix recommended posts layout.
Fix recommended posts page to use new post gallery component.
2021-12-05 03:37:56 -06:00
evazion
40568a9843 posts: fix parent/child post layout.
Fix regression causing parent/child posts to be laid out as a grid
instead of as a single row of posts.
2021-12-05 02:52:08 -06:00
evazion
2e6f480d07 pools: fix pool gallery page layout.
Fix the /pools/gallery page layout being broken by 8841de68a.

This required refactoring the PostGalleryComponent to take a set of
PostPreviewComponents instead of a set of Posts.

The upshot is that it's technically possible to have adjustable
thumbnail sizes on the pool gallery page now (although this is not yet
exposed in the UI).
2021-12-05 02:52:07 -06:00
evazion
8841de68ac posts: add adjustable thumbnail sizes (#4932).
Add a menu in the top right of the post index page that lets you select
the thumbnail size.

This menu is currently hidden until the new thumbnails have been generated.

On desktop, there are five thumbnail sizes:

* Small:    150x150 (https://danbooru.donmai.us/posts?size=150)
* Medium:   180x180 (https://danbooru.donmai.us/posts?size=180)
* Large:    225x225 (https://danbooru.donmai.us/posts?size=225)
* Huge:     270x270 (https://danbooru.donmai.us/posts?size=270)
* Gigantic: 360x360 (https://danbooru.donmai.us/posts?size=360)

On mobile, there are four sizes:

* Small:  150x150 / 3 posts per row (https://danbooru.donmai.us/posts?size=150)
* Medium: 180x180 / 2 posts per row (https://danbooru.donmai.us/posts?size=180)
* Large:  225x225 / 2 posts per row (https://danbooru.donmai.us/posts?size=225)
* Huge:   360x360 / 1 posts per row (https://danbooru.donmai.us/posts?size=360)

There are two extra sizes that aren't listed in the menu:

* 225x360 (https://danbooru.donmai.us/posts?size=225w)
* 270x360 (https://danbooru.donmai.us/posts?size=270w)

These sizes are good for tall thumbnails, but not so much for wide
thumbnails. They aren't listed because in practice they're a bit too big.

The 225x225 and 270x270 sizes are really just 360x360 thumbnails scaled
down in HTML. This means 225x225 and 360x360 thumbnails both use the
same amount of bandwidth.

Thumbnail size is currently a per-search option, not a persistent
account-level setting.

This changes the HTML structure of thumbnails somewhat, so this may
break userscripts and custom CSS.
2021-12-04 06:30:29 -06:00
evazion
17537084fe posts: generate 180x180px and 360x360px thumbnails (#4932).
Add two new thumbnail sizes. These new thumbnail sizes are generated on
upload, but not used yet.
2021-12-02 23:42:44 -06:00
evazion
9e77ff4948 posts: disable cropped (square) thumbnails on mobile.
Disable cropped (square) thumbnails on mobile. Use regular uncropped
thumbnails instead.

This is for a few reasons:

* It made it harder to support multiple thumbnail sizes or file formats,
  since we need a cropped and uncropped version for every size and format.
* The cropping algorithm wasn't that great and sometimes cropped out
  important parts of the image.
* The thumbnail type (cropped or uncropped) was automatically chosen
  clientside based on the user's screen size, which made certain things
  like adjustable thumbnail sizes more difficult because we didn't know
  which thumbnail type the user actually had.

This may return again as an option in the future, but for now it's disabled.
2021-12-02 23:32:23 -06:00
evazion
e8f9e3ab28 posts: show 2 posts per row on mobile instead of 3.
Three thumbnails per row was pretty tight for most phones since the most
common phone resolution is 360x640. Two thumbnails per row lets us have
thumbnails up to 180x180 in size.
2021-12-02 23:32:17 -06:00
evazion
74e28e14b8 posts: factor out post gallery component.
Factor out thumbnail galleries into a PostGallery component.

This changes the html structure so that post galleries on all pages are
always wrapped in a `.posts-container` class. This fixes an issue with
thumbnails on the pool show page not being aligned correctly on mobile,
like they are on the post index page. This also affected thumbnail
galleries on other pages, like wiki pages and user profiles.
2021-12-02 22:18:00 -06:00
evazion
15657aad6d emails: update email domain whitelist. 2021-12-02 20:49:20 -06:00
evazion
6fc0854b4c Remove StorageManager::SFTP.
Remove the SFTP file storage backend. Downstream users can use either
sshfs (which is what Danbooru now uses in production) or rclone instead.
The Ruby SFTP gem was much slower than sshfs.
2021-12-01 23:46:20 -06:00
evazion
5bf4e31c25 users: fix incorrect vote counts on user profile pages.
Deleted comment votes and post votes were being incorrectly counted.
2021-12-01 04:47:47 -06:00
evazion
f86e16cfbd MediaFile: allow generating thumbnails for corrupt files.
We need this so we can regenerate thumbnails for old posts with
corrupted images.
2021-12-01 04:45:26 -06:00
evazion
2ffe973275 MediaFile: add support for creating .webp and .avif thumbnails.
These other formats aren't actually generated during upload, but support
for creating them is there.

Also tune the parameters for generating JPEGs:

* Use Q=85 instead of Q=90 because Q=85 enables 4:2:0 chroma
  subsampling, while Q=90 doesn't use subsampling. Subsampling reduces
  filesize by ~30% in most cases. It does reduce quality for certain
  images, particularly for images with lots of bright red, but in most
  cases the quality difference isn't noticeable.

* Enable several MozJPEG-specific options, including trellis
  quantization and scan optimization. These reduce filesize without
  reducing quality, at the cost of slower encoding times.
2021-12-01 04:45:26 -06:00