This is the scenario: * You type something in autocomplete, let's say 'touhou'. * Autocomplete calls /autocomplete?search[query]=touhou&search[type]=tag_query * The endpoint returns JSON, because the autocomplete call sets an `Accept: application/json` header requesting JSON. * Visit /autocomplete?search[query]=touhou&search[type]=tag_query in your browser. * Notice that the cached JSON response is incorrectly returned, not an HTML response like the browser requested. The problem is that the response type is chosen based on the Accept header, but the response didn't set the `Vary: Accept` header, so the browser doesn't know the response type can vary and so it incorrectly returns the cached response. This issue is partially fixed by Rails 6.1 ([1]), which properly sets the `Vary: Accept` header when the response depends on the Accept header. However, the next issue is that Cloudflare doesn't respect the Vary header at all ([2], [3]). Therefore we can't use the Accept header to pick the format, instead we have explicitly specify the format with /autocomplete.json. This is clearer and better for caching anyway. Using the `Vary: Accept` header reduces the cache hit rate, because the exact format of the Accept header varies across browsers, which fragments the cache. Whew. [1] https://github.com/rails/rails/pull.36213 [2] https://community.cloudflare.com/t/cloudflare-cdn-cache-to-support-http-vary-header/160802 [3] https://support.cloudflare.com/hc/en-us/articles/115003206852 [4] https://www.smashingmagazine.com/2017/11/understanding-vary-header/
Installation
It is recommended that you install Danbooru on a Debian-based system since most of the required packages are available on APT. Danbooru has been successfully installed on Fedora, CentOS, FreeBSD, and OS X. The INSTALL.debian install script is straightforward and should be simple to adapt for other platforms.
For best performance, you will need at least 256MB of RAM for PostgreSQL and Rails. The memory requirement will grow as your database gets bigger.
On production Danbooru uses PostgreSQL 9.4, but any 9.x release should work.
Use your operating system's package management system whenever possible. This will simplify the process of installing init scripts, which will not always happen when compiling from source.
Troubleshooting
These instructions won't work for everyone. If your setup is not working, here are the steps I usually recommend to people:
-
Test the database. Make sure you can connect to it using psql. Make sure the tables exist. If this fails, you need to work on correctly installing PostgreSQL, importing the initial schema, and running the migrations.
-
Test the Rails database connection by using rails console. Run Post.count to make sure Rails can connect to the database. If this fails, you need to make sure your Danbooru configuration files are correct.
-
Test Nginx to make sure it's working correctly. You may need to debug your Nginx configuration file.
-
Check all log files.
Services
Danbooru employs numerous external services to delegate some functionality.
For development purposes, you can just run mocked version of these
services. They're available in scripts/mock_services and can be started
automatically using Foreman and the provided Procfile.
Amazon Web Services
In order to enable the following features, you will need an AWS SQS account:
- Pool versions
- Post versions
- IQDB
- Saved searches
- Related tags
Google APIs
The following features requires a Google API account:
- Bulk revert
- Post versions report
IQDB Service
IQDB integration is delegated to the IQDBS service.
Archive Service
In order to access versioned data for pools and posts you will need to install and configure the Archives service.
Reportbooru Service
The following features are delegated to the Reportbooru service:
- Related tags
- Missed searches report
- Popular searches report
- Favorite searches
- Upload trend graphs
Recommender Service
Post recommendations require the Recommender service.
Cropped Thumbnails
There's optional support for cropped thumbnails. This relies on installing
libvips-8.6 or higher and setting Danbooru.config.enable_image_cropping
to true.