Commit Graph

10990 Commits

Author SHA1 Message Date
evazion
163ba8e7da posts: micro-optimize allocations during thumbnail generation.
Do a few micro-optimizations to reduce the number of memory allocations
during thumbnail generation.

This commit, combined with freezing string literals in a7dc05 and
67b961, reduces the number of allocations on the front page from 180,000
to 150,000, and the number of retained objects from 8,000 to 4,000.
2021-12-16 00:53:48 -06:00
evazion
3fcecd59a8 Add derailed_benchmarks gem. 2021-12-16 00:53:48 -06:00
evazion
51a4daef47 Update Rails from 6.1.4.3 to 6.1.4.4.
Fixes this bug:

    There was a bug in the previous release such that requests in
    development with a port number wouldn’t be considered “authorized”
    requests. Requests to “127.0.0.1:3000” and custom hosts should work
    in this new version.

https://weblog.rubyonrails.org/2021/12/15/Rails-6-0-4-4-and-6-1-4-4-have-been-released/
2021-12-15 21:40:24 -06:00
evazion
a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00
evazion
67b96135dd Make Symbol#to_s return frozen string.
Monkey-patch Symbol#to_s to return a frozen (immutable) string instead
of a mutable string.

This should reduce string allocations, and thereby reduce memory usage
and garbage collector pressure, but it may be incompatible with
libraries that expect Symbol#to_s to return a mutable string.

https://bugs.ruby-lang.org/issues/16150
https://github.com/Shopify/symbol-fstring
2021-12-14 21:33:27 -06:00
evazion
4e730a145d Update Ruby gems and Yarn packages. 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
aeb2b2b7ae tests: fix session_loader_test.
Fix regression in 52013eac1.
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
fd127cbaba rake: fix syntax error in danbooru:images:validate rake task. 2021-12-08 21:30:33 -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
e57e38b35f tests: fix broken tests. 2021-12-08 03:01:54 -06:00
evazion
08bcd51ac8 media assets: add rake task to validate thumbnails.
Update `bin/rails danbooru:images:validate` to work on media assets
instead of posts, and to check that all thumbnails exist.
2021-12-07 18:01:21 -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
3d4d8ae2ae media assets: fix thumbnail backfill script to ignore Flash files.
We can't generate thumbnails for Flash files, so ignore them.
2021-12-05 21:48:57 -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
d47154a9a6 media assets: fix typo in thumbnail backfill script. 2021-12-05 19:04:21 -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
bcc773390b media assets: add script to backfill new thumbnail sizes. 2021-12-05 16:41:32 -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