Commit Graph

1111 Commits

Author SHA1 Message Date
evazion
6dd331745a Rewrite related tags implementation.
Rewrite the implementation of related tags to be simpler, faster, and
more accurate:

* The related tags are now calculated by taking a random sample of 1000
  posts, finding the top 250 most frequent tags among those posts, then
  ordering those tags by cosine similarity.

* Related tags can generally be calculated in 50-300ms at these sample
  sizes. Very high sample sizes (25000+ posts) are still relatively fast
  (1-3 seconds), but generally they don't improve accuracy much.

* Related tags are now cached in redis rather than in the tags table.
  The related_tags column in the tags table is no longer used.

* Only the related tags in the search taglist are cached. The related
  tags returned by the 'Related tags' button are not cached.

* The cache lifetime is a fixed 4 hours.

* The 'Related tags' button now works with metatags.

* The /related_tag page now works with metatags and multitag searches.

Fixes #4134, #4146.
2019-08-30 20:03:36 -05:00
evazion
7b8584e3b0 Model#search: refactor searching for attributes. 2019-08-29 20:44:33 -05:00
evazion
8756480500 search: drop special case for pixiv urls in source: metatag.
* Drop support for `source:pixiv/artist-name` searches. This was a hack
  that only worked on old pixiv urls that haven't been used for years.
* Replace the old SourcePattern(lower(source)) index with a trigram index.
2019-08-29 02:06:35 -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
eba6440b8b Fix #4144: Deviantart Eclipse update broke strategy. 2019-08-28 23:40:29 -05:00
evazion
0df5c0fd2b Replace deprecated update_attributes with update.
https://rubyinrails.com/2019/04/09/rails-6-1-activerecord-deprecates-update-attributes-methods/

DEPRECATION WARNING: update_attributes! is deprecated and will be removed from Rails 6.1 (please, use update! instead)
2019-08-25 20:29:32 -05:00
evazion
1a964f7a10 app controller: move safe mode from app controller to SessionLoader. 2019-08-24 22:55:36 -05:00
evazion
a9b0362fc7 Fix #4125: Detect forum and comment spam. 2019-08-23 22:41:47 -05:00
evazion
06ff249530 dmails: factor out spam detector service. 2019-08-23 22:38:03 -05:00
evazion
70e0d2fac2 tag change notices: use cache instead of using redis directly. 2019-08-22 23:28:49 -05:00
evazion
e03f6b9bc0 tests: drop PostSets::Pool tests.
We no longer use this class for pool show pages. Only used by
inheritance by PostSets::FavoriteGroup.
2019-08-22 21:30:00 -05:00
evazion
6ba3d68792 dmails: fix feedback not being left when spammer is autobanned. 2019-08-22 21:29:58 -05:00
evazion
d05ebfe116 dmails: fix bug preventing members from sending dmails.
Bug: sending dmails failed for members.

Cause: using lambdas with `rakismet_attrs` failed because unexpected
arguments are passed to the lambdas. Using procs works because the
arguments are ignored.

Also fix the tests to actually test akismet. We didn't catch this
because the tests mocked out the `spam?` call.
2019-08-22 00:42:49 -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
dab43d96c9 jobs: migrate mass updates to ActiveJob.
Also fixes a bug where mod actions weren't logged on mass updates.
Creating the mod action silently failed because it was called when
CurrentUser wasn' set.
2019-08-19 00:46:31 -05:00
evazion
2b033443db tests: fix user name change test (fixup for 59b277ead). 2019-08-19 00:46:30 -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
7871dced00 users: fix find_by_name, name_to_id to strip whitespace.
Fix find_by_name and name_to_id to use normalize_name properly, so that
they ignore leading/trailing whitespace. This fixes various search forms
failing to return results when the username field contains trailing
whitespace (inserted by autocomplete).
2019-08-18 11:24:42 -05:00
evazion
82fbb19e0f users: drop unused code. 2019-08-18 11:24:42 -05:00
evazion
27a118dfc8 tests: drop timecop gem. 2019-08-18 11:24:41 -05:00
evazion
145894fe8b tests: fix alias/implication tests. 2019-08-17 02:41:07 -05:00
evazion
2b6361369e jobs: migrate aliases/implications to ActiveJob. 2019-08-16 20:49:35 -05:00
evazion
2bbdc5d143 jobs: migrate saved searches to ActiveJob.
* Fix tests to run the searches for real instead of mocking everything out.

* Fix SavedSearch.populate to only use the read only database in
  production because in breaks things in tests. Specifically:
  the posts get created in one db connection but searched for in
  another, but the second transaction doesn't see the uncommitted posts
  in the first transaction, so the search doesn't work.
2019-08-16 20:49:35 -05:00
evazion
a68db501c2 jobs: migrate related tag updates to ActiveJob. 2019-08-16 20:49:35 -05:00
evazion
24eb1b155f jobs: migrate pool category updates to ActiveJob. 2019-08-16 20:49:34 -05:00
evazion
4e8b3d9310 jobs: migrate user deletions to ActiveJob. 2019-08-16 20:49:34 -05:00
evazion
817f5ecf9c jobs: drop favgroup expunge job.
Make `Post#expunge!` remove favgroups synchronously.
2019-08-16 20:49:34 -05:00
evazion
bb157f5d5b models: drop various unused #named methods. 2019-08-15 19:18:19 -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
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
evazion
247d825618 tests: fixup Post.fast_count test (a6163258b). 2019-08-15 00:36:25 -05:00
evazion
b50b7f2a91 tag aliases: fix bug in alias resolution.
Bug: Searching for an aliased tag returns an empty page instead of
showing the results for the real tag.

Cause: The query parsing code runs the search string through
`.mb_chars.downcase` before calling `TagAlias.to_aliased`, so the input
to `to_aliased` is actually a ActiveSupport::Multibyte::Chars object.
This breaks the `aliases[name]` hash lookup because `name` is not a
plain string.

Fixup for c7bcce429.
2019-08-12 18:10:49 -05:00
evazion
a71899559a tests: fix ip ban test regression. 2019-08-12 14:17:00 -05:00
evazion
7316f41d1d Fix #4106: Allow moderators to IP ban subnets. 2019-08-12 02:12:56 -05:00
evazion
18a216c67a Fix #4130: Remove tag alias corrections. 2019-08-10 22:46:49 -05:00
evazion
c7bcce429e Fix #4129: Remove tag alias caching. 2019-08-10 22:04:55 -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
evazion
a8896b664d twitter: fix batch bookmarklet selecting wrong image.
Fix regression in 7e465aeda.

https://danbooru.donmai.us/forum_topics/9127?page=276#forum_post_158779
2019-08-06 10:42:45 -05:00
evazion
d0c28d79f0 tests: temp disable broken tests.
Broken by bug in shoulda-context-1.2.2. Uncomment after upgrading to
shoulda-context-2.0.0.
2019-08-05 13:41:06 -05:00
evazion
7e465aedae Fix #4110: New Twitter image urls are broken in bookmarklet. 2019-08-04 20:23:10 -05:00
evazion
9ecf36585c nijie: update for new image urls.
Nijie moved from this:

    https://pic03.nijie.info/nijie_picture/236014_20170620101426_0.png (page: https://www.nijie.info/view.php?id=218856)

to this:

    https://pic.nijie.net/03/nijie_picture/236014_20170620101426_0.png (page: https://www.nijie.info/view.php?id=218856)
2019-08-04 17:49:54 -05:00
evazion
39bd766b34 Fix #4053: Add disapproval index improvements.
Add search form to /moderator/post/disapprovals.
2019-08-02 22:03:03 -05:00
evazion
6c69165780 Fix #4105: IP bans leak banned IPs in /mod_actions. 2019-08-01 21:21:18 -05:00
evazion
065609ff4f artists: prevent creating artist entries for non-artist tags (#4107, 2717).
Validate that artist entries belong to an artist tag. Don't allow
creating artist entries for character/copyright/meta tags, but do allow
entries for general tags (the gentag will be automatically changed to an
artist tag).
2019-08-01 20:20:06 -05:00
evazion
bcaefa0a7e Fix #4107: Can't create artist entry if tag already has a wiki #4107 2019-08-01 19:34:21 -05:00
Albert Yi
f95bcc7330 move safe_mode from Thread.current to RequestStore 2019-06-26 09:26:20 -07:00
Albert Yi
04edc3f533 update factories + tests 2019-05-10 17:31:07 -07:00
Albert Yi
6612aa1af9 fix unit tests 2019-04-25 18:13:59 -07:00
Albert Yi
6f4ca75bb1 try to handle deivantart images hosted on images-wixmp better 2019-04-16 13:55:26 -07:00
Albert Yi
eb8ce2e955 Revert "eliminate old algorithm for deviant art sources, fix canonical_url on deviantart"
This reverts commit 58ca52b43e.
2019-04-16 13:22:09 -07:00