Commit Graph

723 Commits

Author SHA1 Message Date
evazion
153a8339ab Inherit errors from StandardError instead of Exception. 2020-01-11 19:07:28 -06:00
evazion
aff3d3b18f Fix various rubocop issues. 2020-01-11 19:01:40 -06:00
evazion
bab656a873 config: remove more obsolete or unneeded config options.
Remove more config options that were either unused or that shouldn't
need to be configured by downstream users.
2020-01-11 01:31:29 -06:00
evazion
9afce59790 Merge pull request #4253 from BrokenEagle/missing-post-attributes
Fix missing post HTML attributes
2020-01-10 20:24:51 -06:00
evazion
fc06a2a0f7 posts: fix members not being able to tag posts.
Fix regression caused by 3d3f61559. This is what happened:

* The posts controller calls post.visible? before post.update.
* post.visible? calls post.tag_array.
* The call to tag_array causes the current value of tag_string to be
  cached in @tag_array.
* post.update calls post.merge_old_changes.
* post.merge_old_changes accesses tag_array, which contains the old
  cached version of tag_string rather than the new version from the
  update.
* post.merge_old_changes detects no changes, so the update does nothing.
* This only happens for Members because for Gold+ users the call to
  post.visible? short circuits before accessing tag_array.

Moral of the story: cache invalidation is hard. Don't cache unless you have to.
2020-01-09 18:54:03 -06:00
BrokenEagle
6127492361 Fix missing post HTML attributes 2020-01-09 21:15:31 +00:00
evazion
3d3f615591 config: refactor restricted tag settings. 2020-01-07 19:19:22 -06:00
BrokenEagle
223a6df5d8 Add API data to show/index views 2020-01-04 22:02:44 +00:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
b038761fa7 Post.fast_count: fix post count estimates when there are no posts.
Bug: Post.fast_count failed when Danbooru.config.estimate_post_counts
was enabled but the database didn't have any posts. This normally
happened only during testing.
2019-12-16 18:49:43 -06:00
evazion
518de2fdec cloudflare: fix purging of cached urls.
* Switch CloudflareService from HttpartyCache to Danbooru::Http.

* Purge cached urls from Cloudflare when a post is replaced and the md5
  doesn't change. This happens when a corrupted image is replaced or
  thumbnails are regenerated. Before we purged urls when a post was
  expunged, which was unneeded because those urls can expire naturally.
  It was also wrong because the subdomains were hardcoded, the urls used
  http:// instead of https://, and we didn't account for tagged urls.
2019-12-15 14:03:15 -06:00
evazion
2c6567b5d2 Remove uses of the read replica database.
https://danbooru.donmai.us/forum_topics/9127?page=283#forum_post_160508

There was a recent outage that was caused by the read replica
(yukinoshita.donmai.us) being temporarily unavailable. The pg driver in
rails got hardstuck trying to connect to the replica, which brought down
the whole site. The app servers stopped responding and could only be
brought down with SIGKILL. Even try to boot the rails console didn't
work.

We only really used this to calculate tag counts inside Post.fast_count,
which wasn't really beneficial since the read replica is slower than the
main database.
2019-10-22 12:15:46 -05:00
evazion
82af426592 Remove reference to google-api-client gem (fixup b2d0d2689). 2019-09-28 12:06:42 -05:00
evazion
03d9b3feca pixiv: support new https://www.pixiv.net/artworks/:id urls. 2019-09-24 03:33:21 -05:00
evazion
5f43401b7b Fix #4175: Twitter no longer redirects tweet links for non-existent handles. 2019-09-22 02:58:09 -05:00
evazion
763ac1a7e0 pools: stop maintaining pool category pseudotags in pool strings (#4160)
Stop maintaining pool category pseudo tags (pool:series, pool:collection)
in pool strings. They're no longer used and the changes to the
`Post#pools` method in dc4d2e54b caused issues with this.

Also allow Members to change the category of large pools again. This was
only restricted because maintaining these pseudotags forced us to update
every post in the pool whenever a pool's category was changed.
2019-09-08 23:28:02 -05:00
evazion
d0f060d8eb api: refactor api attribute declarations.
Replace the `method_attributes` and `hidden_attributes` methods with
`api_attributes`. `api_attributes` can be used as a class macro:

    # include only the given attributes.
    api_attributes :id, :created_at, :creator_name, ...

    # include all default attributes plus the `creator_name` method.
    api_attributes including: [:creator_name]

or as an instance method:

    def api_attributes
       [:id, :created_at, :creator_name, ...]
    end

By default, all attributes are included except for IP addresses and
tsvector columns.
2019-09-08 23:28:02 -05:00
evazion
31c7386b9e posts: fixup set_pool_category_pseudo_tags on new posts.
Calling set_pool_category_pseudo_tags before saving the post doesn't
work on new posts because they don't have an id yet, so trying to get
the pools by post id in `Post#pools` fails.
2019-09-08 15:32:31 -05:00
evazion
dc4d2e54b2 pools: stop using the pool_string field (#4160).
Stop using the pool_string field internally, but keep maintaining it
until we can drop it later.

* Stop using the pool_string for `pool:<name>` metatag searches.
* Stop using the pool_string in the `Post#pools` method. This is used to
  get the list of pools on post show pages.
2019-09-08 00:11:57 -05:00
evazion
416f817f6d Post.fast_count: fix incorrect counts for aliased tags.
Revert optimization from a6163258b. Turns out that we have to resolve
aliases in fast_count, otherwise for aliased tags we'll return an empty
count.

Fixes #4156.
2019-09-04 23:56:12 -05:00
evazion
d56b56a6a1 Drop post updates table. 2019-08-29 00:52:23 -05:00
evazion
b283281e5e comments: minimize sql queries.
Certain parts of comment rendering triggered sql queries that we didn't
really need to do. Rework things to avoid this.

* Preload comment creators in order to display commenter names with link_to_user.

* Preload comment votes in order to display "undo vote" links. Only preload
  votes for members since anonymous users can't vote and don't have "undo
  vote" links.

* Rework various conditionals to do the filtering in Ruby so that we
  avoid issuing any extra queries in sql.

* Avoid issuing any queries at all when the post doesn't have any
  comments (when last_commented_at is blank).
2019-08-20 21:55:25 -05:00
evazion
59b277ead1 users: drop id_to_name, name_to_id caching.
Changes:

* Drop Users.id_to_name.
* Don't cache Users.name_to_id.
* Replace calls to name_to_id with find_by_name when possible.
* Don't autodefine creator_name in belongs_to_creator.
* Don't autodefine updater_name in belongs_to_updater.
* Instead manually define creator_name / updater_name only on models that need
  to return these fields in the api.

id_to_name was cached to reduce the impact of N+1 query patterns in
certain places, especially in api responses that return creator_name /
updater_name fields. But it still meant we were doing N calls to
memcache. Using `includes` to prefetch users avoids this N+1 pattern.

name_to_id had no need be cached, it was never used in any performance-
sensitive contexts.

Avoiding caching also avoids the need to keep these caches consistent.
2019-08-18 11:24:42 -05:00
evazion
868a2256d1 jobs: migrate file deletion jobs to ActiveJob. 2019-08-16 20:49:35 -05:00
evazion
817f5ecf9c jobs: drop favgroup expunge job.
Make `Post#expunge!` remove favgroups synchronously.
2019-08-16 20:49:34 -05:00
evazion
798d524e60 Post#tag_match: clean up read_only param.
* Drop /posts?ro=true param (broken).
* Clean up tag_match (rescuing PG::ConnectionBad didn't do anything, we
  just build the query here, we don't run it).
2019-08-16 00:26:00 -05:00
evazion
b9d35eaf2c Fix #3272: Unicode tags are still being allowed.
* Don't allow adding tags with invalid names when they already exist in
  the tags table.
* If an invalid tag is added, show an warning and ignore the tag instead
  of failing with a hard error.
* Move the _(cosplay) tag validation into the tag name validator.
2019-08-15 16:42:23 -05:00
evazion
d8749e7dfe search: save a query in fast_count (#4120).
During single-tag searches we look up the tag once in Post.fast_count
and later on when rendering the wiki excerpt. Doing a raw query here
meant that Rails couldn't cache the query, so it got ran again when
rendering the excerpt.
2019-08-12 13:38:45 -05:00
evazion
a6163258bf Post.fast_count: skip alias normalization.
Post.fast_count calls Tag.normalize_query to normalize the tag string
used for the pfc cache key. This slightly improves cache sharing at the
expense of an extra query during tag searches. The extra query isn't
worth it.
2019-08-12 13:38:45 -05:00
evazion
5231371100 posts: drop img.ly source normalization.
There are only two posts from this site and the site itself is defunct:

* https://danbooru.donmai.us/posts/1561685
* https://danbooru.donmai.us/posts/1412508
* https://img.ly/ofxl
2019-08-07 22:11:07 -05:00
evazion
7f482dc35b deviantart: normalize wixmp.com sources to page urls.
Normalize sources like this:

   https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/ab917938-d8c1-4b58-933d-0d38c390461f/ddcyi98-cbd39da2-f528-4b26-aadb-a16fe91442b2.jpg/v1/fill/w_1280,h_1760,q_100,strp/tifa_by_chubymi_ddcyi98-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTc2MCIsInBhdGgiOiJcL2ZcL2FiOTE3OTM4LWQ4YzEtNGI1OC05MzNkLTBkMzhjMzkwNDYxZlwvZGRjeWk5OC1jYmQzOWRhMi1mNTI4LTRiMjYtYWFkYi1hMTZmZTkxNDQyYjIuanBnIiwid2lkdGgiOiI8PTEyODAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.Uochlma4QJmLwL2ZGMmvTr4HMva4m4bCeF3vnyPSw4I

to this:

   https://www.deviantart.com/chubymi/art/Tifa-807825644

on the sidebar of the posts show page.
2019-08-06 12:04:05 -05:00
Albert Yi
d8aabff77b remove post keeper references 2019-01-31 15:45:06 -08:00
Albert Yi
d97622d1bb Merge pull request #4007 from evazion/fix-4004
Fix #4004: Add additional order by metatags for posts
2019-01-09 14:43:15 -08:00
evazion
fde398d37b posts: clarify missing artist tag warning (#4029). 2018-12-28 15:52:49 -06:00
evazion
b1335616dd search: add {flag,appeal,approval,replacement,child,pool}_count metatags (#4004). 2018-12-11 18:10:20 -06:00
evazion
4a1f0523a4 search: add comment_count, note_count metatags (#4004).
Add these metatags:

* comment_count
* deleted_comment_count
* active_comment_count
* note_count
* deleted_note_count
* active_note_count
* order:comment_count
* order:deleted_comment_count
* order:active_comment_count
* order:note_count
* order:deleted_note_count
* order:active_note_count
2018-12-11 18:10:20 -06:00
evazion
37b2214472 post_tags_match: replace joins with subqueries.
Refactor various post_tag_match methods to use subqueries instead of joins.

This simplifies things inside PostQueryBuilder, since now we can assume
we're always dealing with a Post relation, rather than some other table
joined with the posts table.
2018-12-11 18:10:20 -06:00
evazion
c7e6c2a44a posts: fix pixiv id parsing (fixup for 5cf6a43) 2018-11-04 14:22:29 -06:00
Albert Yi
e133a598a3 fixes #3936 2018-10-12 15:17:32 -07:00
evazion
e329764276 Fix #3952: Adding animated_gif tag to a ugoira post breaks the player. 2018-10-10 23:50:36 -05:00
evazion
fdb6e4ecee moebooru: rewrite konachan urls for Post#normalized_source (#3911). 2018-10-06 00:58:22 -05:00
evazion
bd3fb7d70e Post#normalized_source: fix for yande.re urls.
Fix regex for yande.re urls like this:

    https://files.yande.re/image/b66909b940e8d77accab7c9b25aa4dc3/yande.re%20377828.png
2018-10-01 20:03:21 -05:00
Albert Yi
02156f3f34 Merge pull request #3933 from evazion/fix-tag-set-presenter
Optimize tag set presenters
2018-10-01 12:55:05 -07:00
evazion
35eaf28822 Post#fast_count: lower timeout to 1 second. 2018-10-01 12:55:57 -05:00
evazion
ccb57e802c Fix #3934: Post#fast_count has very slow worst case behavior. 2018-10-01 12:55:57 -05:00
evazion
2ae7ec42df Post#fast_count: raise min cache lifetime to 3 minutes (#3925). 2018-10-01 10:38:15 -05:00
evazion
4425150298 Post#fast_count: fix cache expiry not being set (#3925). 2018-10-01 10:38:15 -05:00
evazion
88a177e1d5 TagSetPresenter: refactor humanized_essential_tag_string.
Move Post#humanized_essential_tag_string to TagSetPresenter#humanized_essential_tag_string.

This allows humanized_essential_tag_string to reuse the same set of tags
already fetched by the tag set presenter for the sidebar.

This avoids fetching the tag categories from memcache again (via
Post#typed_tags) when we're already fetched the tags once before.

This also means it's no longer necessary to cache humanized_essential_tag_string
itself in memcache, since it can be generated as quickly as the sidebar taglist.
2018-09-30 21:52:24 -05:00
evazion
2cc4e35cc9 Fix #3930: Can't remove children from a parent post through child: metatag.
Add `child:none` and `-child:123` edit metatags. Allow using ranges with
these metatags (e.g. `-child:1..10`, `child:1,3,5`).
2018-09-29 20:42:38 -05:00
evazion
03abbd0683 Fix #2894: Use [[:space:]] instead of \s in regexes. 2018-09-20 19:24:38 -05:00