Commit Graph

291 Commits

Author SHA1 Message Date
evazion
f73d2e3956 reports: add ability to group reports by column.
Add ability to group reports by various columns. For example, you can see
the posts by the top 10 uploaders over time, or posts grouped by rating
over time.
2022-10-22 04:05:10 -05:00
evazion
2989ba1854 Update Ruby gems and Yarn packages. 2022-10-18 19:17:26 -05:00
evazion
a9fe73a483 ai tags: save ai tags on upload.
Save the AI tags when a media asset is uploaded.
2022-06-28 03:12:46 -05:00
evazion
04359d67f4 discord: update /tagme command to use new autotagger service. 2022-06-27 01:40:44 -05:00
evazion
910846163d Fix #5094: db/populate.rb is broken.
Rewrite db/populate.rb:

* Fix broken code.
* Pull random posts from Danbooru for more realistic data.
* Generate more data (wiki pages, artist commentaries, artist urls).
* Make the amount of data generated configurable with environment variables.
* Use FFaker to generate better random text and usernames.

Usage:

* docker-compose exec danbooru bin/rails runner db/populate.rb # with Docker
* bin/rails runner db/populate.rb                              # without Docker
2022-05-08 22:56:08 -05:00
evazion
e698bf91ee gems: replace pry with debug.
Replace the 'pry' gem with the 'debug' gem. The debug gem is the new
standard debugger in Ruby 3.1.

Use `binding.break` instead of `binding.pry` to set breakpoints.

Install the extension below for VS Code support.

https://github.com/ruby/debug#how-to-use
https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg
2022-04-23 21:16:37 -05:00
evazion
f69847fc59 Add Elastic APM integration.
https://www.elastic.co/guide/en/apm/agent/ruby/4.x/introduction.html
2022-04-12 20:49:10 -05:00
evazion
98b313f8de Remove NewRelic integration.
Remove the NewRelic integration in preparation for migrating to Elastic APM instead.
2022-04-11 01:46:30 -05:00
evazion
1028bb1c71 Update Ruby gems and Yarn packages. 2022-03-07 04:03:01 -06:00
evazion
926a8fa81f Danbooru::URL: add #basename, #filename, and #file_ext utility methods.
Add `#basename`, `#filename`, and `#file_ext` utility methods to
Danbooru::URL and change a few places to use them. Simplifies parsing
filenames in source URLs in various places.
2022-02-27 02:27:21 -06:00
evazion
fbab273c81 Upgrade http.rb gem to 5.0.4.
Fixes a bug where the Foundation source strategy failed because http.rb
automatically sent a `Content-Length: 0` header with all GET requests,
which caused Foundation to return a 400 Bad Request error. This behavior
was fixed in http.rb 5.x.

http.rb 5.x has a breaking change where it now includes the request object
inside the response object, which we have to handle in a few places.
2022-02-22 00:17:05 -06:00
evazion
54dbf1a436 Update Ruby gems and Yarn packages. 2022-01-17 10:49:04 -06:00
evazion
acf565be7b Fix #4678: Validate custom CSS.
* Make it an error to add invalid custom CSS to your account.
* Add a fix script to remove custom CSS from all accounts with invalid CSS.
2022-01-15 23:20:49 -06:00
evazion
3f25ad6dce rails: upgrade to Rails 7.0.1. 2022-01-07 14:24:45 -06:00
evazion
41a095abfe gems: temp disable meta_request gem.
It's not yet compatible with Rails 7.0.
2022-01-07 12:43:39 -06:00
evazion
3841fba78e jobs: remove DelayedJobs.
Remove the DelayedJobs gem and database table. Completes the transition
to GoodJob started in c06bfa64f and f4953549a.

Downstream users can upgrade as follows:

* Stop the Rails server.
* Stop the DelayedJobs worker (normally running as `bin/delayed_job` or `bin/rails jobs:work`).
* Run `bin/rails jobs:work` to finish any pending delayed jobs.
* Run `bin/rails db:migrate` to create the good_jobs table and drop the delayed_jobs table.
* Start the Rails server again.
* Start the GoodJobs worker with `bin/good_job start`.
2022-01-04 15:58:12 -06:00
evazion
c06bfa64f5 Add GoodJob gem.
This is the first step towards replacing DelayedJob with GoodJob. Compared to
DelayedJob:

* GoodJob supports Rails 7 (DelayedJob is currently a blocker for Rails 7
  because it has a version bound on ActiveRecord <6.2).
* GoodJob has a builtin admin dashboard.
* GoodJob supports threaded job workers.
* GoodJob supports scheduled cronjobs.
* GoodJob supports healthchecks for workers.
* GoodJob uses Postgres notifications instead of polling to pick up new
  jobs. This allows jobs to be picked up faster and scales better with
  large numbers of workers.

https://github.com/bensheldon/good_job
2022-01-02 17:13:41 -06:00
evazion
b5b54f2c78 gems: add rbtrace 2021-12-17 22:23:59 -06:00
evazion
3fcecd59a8 Add derailed_benchmarks gem. 2021-12-16 00:53:48 -06:00
evazion
45dbc7582c Update Ruby gems and Yarn packages. 2021-12-08 03:01:54 -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
908df7921f Add Ruby wrapper around libseccomp.
Add a Ruby wrapper library around the libseccomp library. Seccomp is
used to restrict the syscalls a program can make. See comments in
app/logical/seccomp.rb for further details.

This is not used for anything yet. It's simply adding part of the
sandboxing infrastructure for later use.
2021-11-11 09:20:57 -06:00
evazion
bb6ce66bfe gems: don't load listen and solargraph in test mode.
Only load the `listen` and `solargraph` gems in the development
environment, not the test environment. The `listen` gem automatically
spawns background threads to listen for file changes, in order to
automatically reload code when files change, which we don't want or need
in test mode. These threads can interfere with sandboxing, because they
prevent us from being able to call unshare(2) (which can only be called
from a single-threaded process).
2021-11-11 09:20:57 -06:00
evazion
10f2b41ace gems: re-enable meta_request.
Upstream finally released a new version that fixed the "stack level too
deep" bug on Rails 6.1.
2021-09-27 10:43:29 -05:00
evazion
50d6cdf140 Use pry for rails console in production.
Use pry for `bin/rails console` in production too, not just in
development. Useful for hotfixes in production.
2021-09-27 10:02:27 -05:00
evazion
0fed4b557b Remove Unicorn.
No longer used now that we use Puma in production. If you still used
Unicorn in your install, switch to `bin/rails server` instead. See
config/puma.rb for config settings.
2021-09-20 06:17:57 -05:00
evazion
68769c7c3b Remove Capistrano.
No longer used now that we use Kubernetes to deploy the site instead of
Capistrano.

If you run your own installation of Danbooru, and you used Capistrano to
deploy your site, it is recommended that you switch to either the Docker
Compose file (for personal installs), the Procfile (for non-Dockerized,
development environments), or Kubernetes (for production environments;
see https://github.com/danbooru/danbooru-infrastructure/tree/master/k8s
for Danbooru's production configuration).
2021-09-20 04:57:41 -05:00
evazion
051f2be93f gems: remove whenever gem.
We're now using the `clockwork` gem for cronjobs in production. See
config/initializers/clockwork.rb.
2021-09-20 01:30:52 -05:00
evazion
d854bf6b53 BURs: update posts in parallel.
When processing an alias, rename, implication, mass update, or nuke,
update the posts in parallel. This means that if we alias foo to bar,
for example, then we use four processes at once to retag the posts from
foo to bar.

This doesn't mean that if we have two aliases in a BUR, we process both
aliases in parallel. It simply means that when processing an alias, we
update the posts in parallel for that alias.
2021-09-20 01:12:14 -05:00
evazion
c14e3ec902 Remove staging environment.
We never used any of this stuff. The only environments used are
production, development, and test.
2021-09-16 00:44:26 -05:00
evazion
4cc8dd41ec puma: add rack-timeout gem.
Unlike Unicorn, Puma doesn't have a builtin HTTP request timeout
mechanism, so we have to use Rack::Timeout instead.

See the caveats in the Rack::Timeout documentation [1]. In Unicorn, a
timeout would send a SIGKILL to the worker, immediately killing it. This
would result in a dropped connection and a Cloudflare 502 error to the
user. In Puma, it raises an exception, which we can catch and return a
better error to the user. On the other hand, raising an exception can
potentially corrupt application state if it's sent at the wrong time, or
be delayed indefinitely if the app is stuck in IO or C extension code.

The default request timeout is 65 seconds. 65 seconds is to give things
like HTTP requests on a 60 second timeout enough time to complete. Set
the RACK_REQUEST_TIMEOUT environment variable to change the timeout.

1: https://github.com/sharpstone/rack-timeout#further-documentation
2021-09-12 09:32:12 -05:00
evazion
23b2a37050 puma: add puma worker killer gem. 2021-09-12 05:51:09 -05:00
evazion
0aab81440f puma: add Prometheus metrics exporter.
To test it, run `bin/rails server` then do `curl http://localhost:9393`.

https://github.com/harmjanblok/puma-metrics
2021-09-11 10:09:58 -05:00
evazion
540a3e111a Replace streamio-ffmpeg library.
Replace the streamio-ffmpeg library with our own very thin FFmpeg wrapper.
2021-09-05 06:54:56 -05:00
evazion
88e379f9cc Update DText gem. 2021-08-31 21:48:53 -05:00
evazion
c6855261fe gems: update activerecord-hierarchical_query gem.
The bug that blocked Rails 6.1 support was finally fixed upstream.
2021-06-23 06:23:29 -05:00
evazion
cfe471e0b5 gems: don't require Rubocop in Gemfile.
Requiring isn't necessary because it's a standalone tool, not a library.
2021-06-17 04:17:53 -05:00
evazion
9b59ba780b gems: add solargraph gem
Add the Solargraph gem to enable Ruby language integration for
supporting text editors.

This enables various features, including code completion, inline
documentation, type checking, syntax checking, linting, and jump to
definition/references.

Usage:

  Install Solargraph extension for your editor (see https://solargraph.org/guides)
  Run `bin/solargraph download-core` to install core Ruby language docs.
  Run `bin/solargraph bundle` to install Ruby gem docs.

See also:

* https://github.com/castwide/solargraph
* https://solargraph.org/guides/getting-started
* https://marketplace.visualstudio.com/items?itemName=castwide.solargraph
2021-06-17 04:10:26 -05:00
evazion
f65f24be0b docker: add cron service to compose file. 2021-05-25 01:16:59 -05:00
evazion
4439293bf1 newrelic: fix newrelic starting without license key.
Fix an issue where the New Relic agent always started in the production
environment, even when a license key wasn't configured.

Also make the New Relic agent log to stdout instead of log/newrelic_agent.log.
2021-05-24 21:58:01 -05:00
evazion
ca8bfb9149 Update Ruby gems and Yarn packages. 2021-05-15 02:48:13 -05:00
evazion
de5ade7641 Add bcrypt_pbkdf gem.
Add the bcrypt_pbkdf gem. This is required to be able to use manually
configured SSH keys with the SFTP storage manager.
2021-04-30 04:59:17 -05:00
evazion
b8fa15cf50 gems: temp disable meta_request.
Revert 442d0f8dd. Fix was merged upstream but a new gem hasn't been
released yet.
2021-03-29 03:01:02 -05:00
evazion
442d0f8dd3 gems: remove meta_request fork.
Remove a workaround added in 2c06766c9. meta_request had a bug that
caused Rails to fail to launch under Rails 6.1. The fix was finally
merged upstream.

hxxps://github.com/dejan/rails_panel/pull/177.
2021-03-24 17:37:48 -05:00
evazion
1a7a108d47 discord: add /tagme command. 2021-03-19 04:44:22 -05:00
evazion
2c8c7ff80a discord: add initial slash command integration.
Add initial support for the `/count <tags>` and `/posts <tags>` slash commands.

Slash commands are basically like webhooks; we register a command, and
when anybody types that command in Discord, Discord sends us a HTTP
request that we respond to.

* https://discord.com/developers/docs/interactions/slash-commands
* https://support.discord.com/hc/en-us/articles/1500000368501-Slash-Commands-FAQ
2021-03-11 03:04:10 -06:00
evazion
f235b72b3f Export public database dumps to BigQuery.
* Export daily public database dumps to BigQuery and Google Cloud Storage.
* Only data visible to anonymous users is exported. Some tables have
  null or missing fields because of this.
* The bans table is excluded because some bans have an expires_at
  timestamp set beyond year 9999, which BigQuery doesn't support.
* The favorites table is excluded because it's too slow to dump (it
  doesn't have an id index, which is needed by find_each).
* Version tables are excluded because dumping them every day is
  inefficient, streaming insertions should be used instead.

Links:

* https://console.cloud.google.com/bigquery?project=danbooru1
* https://console.cloud.google.com/storage/browser/danbooru_public
* https://storage.googleapis.com/danbooru_public/data/posts.json
2021-03-10 02:52:16 -06:00
evazion
ba9313c0d7 gems: add benchmark-ips gem to development group. 2021-03-08 03:51:29 -06:00
evazion
340eeec023 Update Ruby gems and Yarn packages. 2021-02-28 17:48:30 -06:00
evazion
1c1d784547 css: rework color scheme to use new color palette.
Add a new color palette and rework all site colors (both light mode and dark mode) to
use the new palette.

This ensures that colors are used consistently, from a carefully designed color palette,
instead of being chosen at random.

Before, colors in light mode were chosen on an ad-hoc basis, which resulted in a lot of
random colors and inconsistent design.

The new palette has 7 hues: red, orange, yellow, green, blue, azure (a lighter blue), and
purple. There's also a greyscale. Each hue has 10 shades of brightness, which (including
grey) gives us 80 total colors.

Colors are named like this:

    var(--red-0);    /* very light red */
    var(--red-2);    /* light red */
    var(--red-5);    /* medium red */
    var(--red-7);    /* dark red */
    var(--red-9);    /* very dark red */
    var(--green-7);  /* dark green */
    var(--blue-5);   /* medium blue */
    var(--purple-3); /* light purple */
                     /* etc */

The color palette is designed to meet the following criteria:

* To have close equivalents to the main colors used in the old color scheme,
  especially tag colors, so that changes to major colors are minimized.
* To produce a set of colors that can be used as as main text colors, as background
  colors, and as accent colors, both in light mode and dark mode.
* To ensure that colors at the same brightness level have the same perceived brightness.
  Green-4, blue-4, red-4, purple-4, etc should all have the same brightness and contrast
  ratios. This way colors look balanced. This is actually a difficult problem, because human
  color perception is non-linear, so you can't just scale brightness values linearly.

There's a color palette test page at https://danbooru.donmai/static/colors

Notable changes to colors in light mode:

* Username colors are the same as tag colors.
* Copyright tags are a deeper purple.
* Builders are a deeper purple (fixes #4626).
* Moderators are green.
* Gold users are orange.
* Parent borders are a darker green.
* Child borders are a darker orange.
* Unsaved notes have a thicker red border.
* Selected notes have a thicker blue (not green) border.
2021-02-22 02:32:49 -06:00