Commit Graph

39 Commits

Author SHA1 Message Date
evazion
f11c46b4f8 uploads: stop pruning uploads. 2022-01-28 04:13:22 -06:00
evazion
f4953549ae jobs: switch from DelayedJob to GoodJob.
Switch the ActiveJob backend from DelayedJob to GoodJob. Differences:

* The job worker is run with `bin/good_job start` instead of `bin/delayed_job`.
* Jobs have an 8 hour timeout instead of a 4 hour timeout.
* Jobs don't automatically retry on failure.
* Finishing jobs are preserved and pruned after 7 days.
2022-01-04 13:52:08 -06:00
evazion
a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00
evazion
5ce36b482f maintenance: disable amcheck job.
Creates too much load and causes creating favorites to time out.
2021-10-09 11:45:36 -05:00
evazion
950bc608c2 maintenance: add job to check for database corruption.
Add a job to run pg_amcheck hourly to check for corrupt database indexes.

https://www.postgresql.org/docs/14/app-pgamcheck.html
2021-10-06 08:08:52 -05:00
evazion
627e8e1013 cron: fix undefined variable in exception handler (again)
Fixup for a1d4408c2.
2021-09-29 06:04:28 -05:00
evazion
4a525c7473 cron: fix maintenance tasks failing to run.
Fix maintenance tasks failing to run in production. In production they
were losing the database connection and not re-establishing it, so they
couldn't queue jobs. `ApplicationRecord.verify!` will check if the
connection is lost and re-establish it if it is.

The database connection was being lost because in production we use a
Kubernetes service IP for the database IP, which is essentially a
virtual IP that maps to the real IP. This mapping is implemented with
IPVS[1][2], which has a default idle connection timeout of 5 minutes. If
the connection isn't used for more than 5 minutes, then it's closed.
Since maintenance only runs once an hour, the database connection would
be lost because it was idle for too long.

1: https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs
2: https://kubernetes.io/blog/2018/07/09/ipvs-based-in-cluster-load-balancing-deep-dive/
2021-09-28 18:06:57 -05:00
evazion
a1d4408c29 cron: fix undefined variable in exception handler. 2021-09-28 16:34:05 -05:00
evazion
3835a63771 cron: fix tasks not being logged.
Fix maintenance tasks not being logged by the cron daemon because
in production the log level defaulted to `error` instead of `info`.
2021-09-27 10:43:06 -05:00
evazion
52bf4a3a6b maintenance: break maintenance tasks into individual jobs.
Break the hourly/daily/weekly/monthly maintenance tasks down into
individual delayed jobs. This way if one task fails, it won't prevent
other tasks from running. Also, jobs can be run in parallel, and can be
individually retried if they fail.
2021-09-26 20:38:30 -05:00
evazion
8738d8a645 Remove deletion appeal thread updater.
It was already disabled before, remove it completely now.
2021-09-22 01:57:45 -05:00
evazion
ec0fce34b7 Fix #4863: Retire deletion appeal thread. 2021-08-21 23:48:20 -05: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
4492610dfe rate limits: rework rate limit implementation.
Rework the rate limit implementation to make it more flexible:

* Allow setting different rate limits for different actions. Before we
  had a single rate limit for all write actions. Now different
  controller endpoints can have different limits.

* Allow actions to be rate limited by user ID, by IP address, or both.
  Before actions were only limited by user ID, which meant non-logged-in
  actions like creating new accounts or attempting to login couldn't be rate
  limited. Also, because actions were limited by user ID only, you could
  use multiple accounts with the same IP to get around limits.

Other changes:

* Remove the API Limit field from user profile pages.
* Remove the `remaining_api_limit` field from the `/profile.json` endpoint.
* Rename the `X-Api-Limit` header to `X-Rate-Limit` and change it from a
  number to a JSON object containing all the rate limit info
  (including the refill rate, the burst factor, the cost of the call,
  and the current limits).
* Fix a potential race condition where, if you flooded requests fast
  enough, you could exceed the rate limit. This was because we checked
  and updated the rate limit in two separate steps, which was racy;
  simultaneous requests could pass the check before the update happened.
  The new code uses some tricky SQL to check and update multiple limits
  in a single statement.
2021-03-05 16:00:54 -06:00
evazion
8f1276b013 appeals: crosspost appeals to deletion appeal thread.
Crosspost pending appeals to the deletion appeal thread. We do this once
per hour so we can batch together multiple appeals into one post.
2020-08-16 17:19:04 -05:00
evazion
85b04887d2 maintenance: fix tag counts hourly instead of daily (#4572). 2020-08-07 09:14:31 -05:00
evazion
8917cc3035 maintenance: prune posts hourly instead of daily. 2020-08-07 09:10:00 -05:00
evazion
3b73861d05 maintenance: fix undefined current user exception.
Possible fix for this exception that happens in production for unclear
reasons:

    NoMethodError: undefined method `is_admin?' for nil:NilClass
    …oru/releases/20200805193154/app/policies/tag_policy.rb:    3:in `can_change_category?'
    …www/danbooru/releases/20200805193154/app/models/tag.rb:  216:in `find_or_create_by_name'
    …www/danbooru/releases/20200805193154/app/models/tag.rb:  193:in `block in create_for_list'
    …www/danbooru/releases/20200805193154/app/models/tag.rb:  193:in `map'
    …www/danbooru/releases/20200805193154/app/models/tag.rb:  193:in `create_for_list'
    …ww/danbooru/releases/20200805193154/app/models/post.rb:  463:in `normalize_tags'
2020-08-07 09:06:23 -05:00
evazion
56ba6c2c58 maintenance: fix post pruning test.
Test mistakenly passed because we used `assert(a, b)` instead of
`assert_equal(a, b)`.
2020-08-07 08:53:38 -05:00
evazion
ed79b623cc Fix #4544: Show limited view of other user's uploads on the upload index.
* Show completed uploads to other users.
* Don't show failed or incomplete uploads to other users.
* Don't show tags to other users.
* Delete completed uploads after 1 hour.
* Delete incomplete uploads after 1 day.
* Delete failed uploads after 3 days.
2020-07-13 19:25:30 -05:00
evazion
cc73f2468b disapprovals: don't dmail uploaders about disapprovals.
Remove sending dmail notifications to uploaders when an upload is
disapproved. These messages are usually confusing and frustrating to
uploaders. They don't know who is sending them and they usually feel
insulted when they get negative messages from anonymous users.
2020-06-28 01:51:41 -05:00
evazion
6fecf5db0e BURs: remove old single alias/implication pruning code.
* Rename TagChangeRequestPruner to BulkUpdateRequestPruner.
* Remove old code for pruning individual alias / implication requests.
2020-03-10 21:23:46 -05:00
evazion
5625458f69 users: refactor password reset flow.
The old password reset flow:

* User requests a password reset.
* Danbooru generates a password reset nonce.
* Danbooru emails user a password reset confirmation link.
* User follows link to password reset confirmation page.
* The link contains a nonce authenticating the user.
* User confirms password reset.
* Danbooru resets user's password to a random string.
* Danbooru emails user their new password in plaintext.

The new password reset flow:

* User requests a password reset.
* Danbooru emails user a password reset link.
* User follows link to password edit page.
* The link contains a signed_user_id param authenticating the user.
* User changes their own password.
2020-03-08 23:18:15 -05:00
evazion
3d410398a3 approver pruner: send weekly warning dmails to inactive approvers.
Send weekly warning dmails to approvers in danger of losing their
approver permissions. Don't send warnings if we're more than three weeks
away from demotion so that approvers aren't warned prematurely.
2020-02-27 00:19:16 -06:00
evazion
ce11485fe0 Remove super voters. 2020-02-23 17:52:38 -06:00
evazion
1591df0351 Remove curated pool updater. 2020-02-23 17:52:38 -06:00
evazion
13528ac2d3 Drop forum subscriptions.
Few people used forum subscriptions (only around 100), and even fewer
people were subscribed to active threads. Most subscriptions were for
old threads that will never be bumped again. The implementation also had
a few problems:

* Unsubscribe links in emails didn't work (they unset the user's
  receive_email_notifications flag, but forum subscriptions didn't
  respect this flag).
* Some users had invalid email addresses, which caused notifications to
  bounce. There was no mechanism for preventing bounces.
* The implementation wasn't scalable. It involved a daily linear scan
  over _all_ forum subscriptions looking for any topics that had been updated.
2020-01-21 00:10:21 -06:00
evazion
79aff89573 maintenance: prune approvers monthly instead of weekly.
* Move approver pruning from a weekly task to a monthly task.
* Move weekly maintenance tasks from Wednesdays at 1:30am to Sundays at
  midnight (UTC).
2020-01-13 13:23:22 -06:00
evazion
c95108d37b maintenance: prevent exceptions from halting daily maintenance.
Fix cases where not all daily maintenance tasks run because some earlier
task raised an exception.
2019-12-28 00:21:56 -06:00
evazion
ac9d06bf79 maintenance: remove hourly upload error checker. 2019-12-23 00:14:38 -06:00
evazion
aaab527baa Move Curated pool updater to Danbooru.
* Move the Curated pool updater from Reportbooru to Danbooru.

* Change the process for selecting curated posts. Previously it was
  every post from the last week with at least three supervotes. This was
  flawed because it included both super-upvotes and super-downvotes. Now
  it's the top 100 posts from the last week, ordered from most super-upvoted
  to least.
2019-11-23 18:19:08 -06:00
evazion
64728c89d8 db: remove tag_aliases.post_count column.
This was only used in autocomplete, but it was unnecessary here because
we could already get the post count from the tags table.
2019-11-17 14:39:41 -06:00
evazion
3096cea2d6 maintenance: fix db timeouts in regenerate_post_counts!
Disable database timeouts durings daily maintenance. Fixes
`regenerate_post_counts!` timing out. Remove calls to without_timeout
because otherwise it will reenable the timeout when trying to restore
the old timeout (see 97cc873a3f).
2019-10-01 22:51:40 -05:00
evazion
bc34fb16a4 tags: automatically fix incorrect tag counts during maintenance.
* Automatically fix all tags with incorrect counts during daily
  maintenance (previously only tags with negative counts were fixed).
* Log fixed tags to NewRelic.
* Remove the ability to manually fix tag counts with the "Fix" button on
  the /tags listing. This is no longer necessary now that tags are
  fixed automatically.
2019-09-25 17:57:11 -05:00
evazion
a932b25608 Fix #4142: Missing images after upload. 2019-09-01 13:10:37 -05:00
evazion
80d881bfcb Fix #4148: Don't prune votes. 2019-08-31 20:09:41 -05:00
evazion
65e53b86b3 Drop support for /cache/tag.json.
Drop support for https://danbooru.donmai.us/cache/tags.json. This was a
nightly dump of the tags table that was originally added in #1012. It
was never documented and never really used except for by the DanbooruUp
extension.
2019-08-29 00:52:23 -05:00
evazion
97cc873a3f maintenenace: fix db timeouts during vacuuming.
Setting the statement timeout at the beginning didn't work because
`PostPruner.new.prune!` clobbers the timeout (it calls `without_timeout`,
which doesn't restore the timeout properly if the timeout was zero).
2019-08-22 17:03:18 -05:00
evazion
5f1226ca92 Rename maintenance.rb -> danbooru_maintenance.rb.
Fixes random test failures caused by ambiguous constant lookup issues
(the `Maintenance` module name was used in multiple conflicting places).
2019-08-15 00:36:25 -05:00