Commit Graph

53 Commits

Author SHA1 Message Date
evazion
88ac91f5f3 search: refactor to pass in the current user explicitly. 2022-09-22 04:31:21 -05:00
evazion
ee638f976f Add /user_actions page.
Add a /user_actions page. This page shows you a global timeline of
(almost) all activity on the site, including uploads, comments, votes,
edits, forum posts, and so on.

The main things it doesn't include are post edits, pool edits, and
favorites (posts and pools live in a separate database, and favorites
don't have the timestamps we need for ordering).

This page is useful for moderation purposes because it lets you see a
history of almost all of a user's activity on a single page.

Currently this page is mod-only. In the future it will be open to all
users, so you can view the history of your own site activity, or the
activity of others.
2022-09-16 05:39:25 -05:00
evazion
a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00
evazion
353e708538 votes: allow admins to remove post votes.
Allow admins to remove votes on posts. This is for fixing vote abuse.

Votes can be removed by going to the vote list on the /post_votes page,
or by clicking on a post's score, then using the "Remove" option in the
"..." dropdown menu next to the vote.

Votes are soft-deleted - they're marked as deleted in the database, but
not fully deleted. Removed votes are only visible to admins, not to
regular users. When a vote is removed by an admin, it leaves a mod
action.

Technically it's possible to undelete votes, but there's no UI for it.
2021-11-23 23:18:54 -06:00
evazion
3ae62d08eb favorites: show favlist when hovering over favcount.
Changes:

* Make it so you can click or hover over a post's favorite count to see
  the list of public favorites.
* Remove the "Show »" button next to the favorite count.
* Make the favorites list visible to all users. Before favorites were
  only visible to Gold users.
* Make the /favorites page show the list of all public favorites,
  instead of redirecting to the current user's favorites.
* Add /posts/:id/favorites endpoint.
* Add /users/:id/favorites endpoint.

This is for several reasons:

* To make viewing favorites work the same way as viewing upvotes.
* To make posts load faster for Gold users. Before, we loaded all the
  favorites when viewing a post, even when the user didn't look at them.
  This made pageloads slower for posts that had hundreds or thousands of
  favorites. Now we only load the favlist if the user hovers over the favcount.
* To make the favorite list visible to all users. Before, it wasn't
  visible to non-Gold users, because of the performance issue listed above.
* To make it more obvious that favorites are public by default. Before,
  since regular users could only see the favcount, they may have
  mistakenly believed other users couldn't see their favorites.
2021-11-20 02:40:18 -06:00
evazion
1653392361 posts: stop updating fav_string attribute.
Stop updating the fav_string attribute on posts. The column still exists
on the table, but is no longer used or updated.

Like the pool_string in 7d503f08, the fav_string was used in the past to
facilitate `fav:X` searches. Posts had a hidden fav_string column that
contained a list of every user who favorited the post. These were
treated like fake hidden tags on the post so that a search for `fav:X`
was treated like a tag search.

The fav_string attribute has been unused for search purposes for a while
now. It was only kept because of technicalities that required
departitioning the favorites table first (340e1008e) before it could be
removed. Basically, removing favorites with `@favorite.destroy` was
slow because Rails always deletes object by ID, but we didn't have an
index on favorites.id, and we couldn't easily add one until the
favorites table was departitioned.

Fixes #4652. See https://github.com/danbooru/danbooru/issues/4652#issuecomment-754993802
for more discussion of issues caused by the fav_string (in short: write
amplification, post table bloat, and favorite inconsistency problems).
2021-10-09 22:36:26 -05:00
evazion
c4a4e77ca5 favorites: order /favorites.json by id.
Order https://danbooru.donmai.us/favorites.json by favorite ID instead
of by post ID. This way you can get a feed of recently added favorites.
Previously this wasn't possible because we didn't have an index on
favorite ID.
2021-10-08 21:26:42 -05:00
evazion
340e1008e9 favorites: merge favorites subtables.
Merge the 100 favorite subtables into a single table.

Previously the favorites table was partitioned by user id into 100
subtables to try to make searching by user id faster. This wasn't really
necessary and probably slower than just making an index on
(favorites.user_id, favorites.id) to satisfy ordfav searches. BTree
indexes are logarithmic so dividing an index by 100 doesn't make it 100
times faster to search; instead it just removes a layer or two from the
tree.

This also adds a uniqueness index on (user_id, post_id) to prevent
duplicate favorites. Previously we had to check for duplicates at the
application layer, which required careful locking to do it correctly.

Finally, this adds an index on favorites.id, which was surprisingly
missing before. This made ordering and deleting favorites by id really
slow because it degraded to a sequential scan.
2021-10-08 21:26:42 -05:00
evazion
7fa23c5fbf users: give all users unlimited favorites.
Let all users have unlimited favorites. Formerly the limit was 10k
favorites for regular members, 20k for Gold, and unlimited for Platinum.

Limiting favorites doesn't make sense since upvotes are unlimited.
2021-10-07 06:27:09 -05:00
evazion
e771c0fca8 searchable: don't automatically include id, created_at, updated_at.
Don't make search methods on models call super in order to search
certain default attributes (id, created_at, updated_at). Simplifies some
magic.
2020-12-16 23:57:07 -06:00
evazion
365e3d75af search: refactor parse_query and build methods.
* Eliminate the `parse_query` method.
* Move all the metatag handling logic from the `build` method
  to `metatag_matches` and helper methods.

This is to get all the main metatag handling logic in one place, inside
`metatag_matches`, so that it's easier to add new metatags and to handle
things like negated metatags more consistently.
2020-04-25 00:47:13 -05:00
evazion
7c71311eef Add /favorites.json endpoint. 2020-02-24 22:42:59 -06:00
evazion
153a8339ab Inherit errors from StandardError instead of Exception. 2020-01-11 19:07:28 -06:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
434f1a0b85 favorites: fix LockWaitTimeout errors.
Favoriting posts sometimes fails with ActiveRecord::LockWaitTimeout
errors. This happens when a user tries to favorite multiple posts in
short succession. In that case we want the lock to block and wait for
the other favorite to go through, not to immediately fail.
2019-08-12 19:20:33 -05:00
evazion
fb91bbc6c5 Fix #3813: Favorite limit can be bypassed. 2018-08-12 14:22:08 -05:00
Albert Yi
72f319ccf3 rename lambda references to use shorthand syntax 2018-05-10 11:18:02 -07:00
r888888888
abce4d2551 Raise error on unpermitted params.
Fail loudly if we forget to whitelist a param instead of silently
ignoring it.

misc models: convert to strong params.

artist commentaries: convert to strong params.

* Disallow changing or setting post_id to a nonexistent post.

artists: convert to strong params.

* Disallow setting `is_banned` in create/update actions. Changing it
  this way instead of with the ban/unban actions would leave the artist in
  a partially banned state.

bans: convert to strong params.

* Disallow changing the user_id after the ban has been created.

comments: convert to strong params.

favorite groups: convert to strong params.

news updates: convert to strong params.

post appeals: convert to strong params.

post flags: convert to strong params.

* Disallow users from setting the `is_deleted` / `is_resolved` flags.

ip bans: convert to strong params.

user feedbacks: convert to strong params.

* Disallow users from setting `disable_dmail_notification` when creating feedbacks.
* Disallow changing the user_id after the feedback has been created.

notes: convert to strong params.

wiki pages: convert to strong params.

* Also fix non-Builders being able to delete wiki pages.

saved searches: convert to strong params.

pools: convert to strong params.

* Disallow setting `post_count` or `is_deleted` in create/update actions.

janitor trials: convert to strong params.

post disapprovals: convert to strong params.

* Factor out quick-mod bar to shared partial.
* Fix quick-mod bar to use `Post#is_approvable?` to determine visibility
  of Approve button.

dmail filters: convert to strong params.

password resets: convert to strong params.

user name change requests: convert to strong params.

posts: convert to strong params.

users: convert to strong params.

* Disallow setting password_hash, last_logged_in_at, last_forum_read_at,
  has_mail, and dmail_filter_attributes[user_id].

* Remove initialize_default_image_size (dead code).

uploads: convert to strong params.

* Remove `initialize_status` because status already defaults to pending
  in the database.

tag aliases/implications: convert to strong params.

tags: convert to strong params.

forum posts: convert to strong params.

* Disallow changing the topic_id after creating the post.
* Disallow setting is_deleted (destroy/undelete actions should be used instead).
* Remove is_sticky / is_locked (nonexistent attributes).

forum topics: convert to strong params.

* merges https://github.com/evazion/danbooru/tree/wip-rails-5.1
* lock pg gem to 0.21 (1.0.0 is incompatible with rails 5.1.4)
* switch to factorybot and change all references

Co-authored-by: r888888888 <r888888888@gmail.com>
Co-authored-by: evazion <noizave@gmail.com>

add diffs
2018-04-06 18:09:57 -07:00
r888888888
0bfd201973 simplify logic 2017-09-13 14:47:42 -07:00
r888888888
1f3bafc061 delegate removal from favorites and updating of user fav counts to delayed job 2017-09-13 14:19:54 -07:00
evazion
af42740ca9 expunge: decrement user favorite counts. 2017-09-13 13:29:35 -07:00
r888888888
d48ed95191 favoritescontroller#destroy should work even if the post doesn't exist, remove from favorites on expunge (fixes #3222) 2017-07-19 13:39:24 -07:00
evazion
c1834ab8dd Inherit models from ApplicationRecord instead of ActiveRecord::Base. 2017-06-16 13:28:31 -05:00
evazion
40feeb2411 Post#give_favorites_to_parent: fix exception (fixup 77793759)
Forgot the `belong_to :user` association in 77793759.
2017-04-04 20:42:31 -05:00
r888888888
bb3eb9f980 favoriting now triggers an upvote 2016-02-22 17:02:15 -08:00
r888888888
fb67525c28 add intro route shortcut, optimize Favorite.remove 2015-12-08 15:17:27 -08:00
r888888888
ab325d48bf optimize favorite delete, ignore statement timeout when expunging posts #2556 2015-12-07 14:53:15 -08:00
r888888888
1253592dc9 fixes #1210 2014-06-22 20:12:06 -07:00
r888888888
e15fb6eac9 Revert "potential fix for #1210"
This reverts commit d5f10f41fd.
2014-06-22 19:43:17 -07:00
r888888888
d5f10f41fd potential fix for #1210 2014-06-20 16:33:29 -07:00
r888888888
fad0ab7c93 fixes #2133 2014-04-16 17:43:34 -07:00
Toks
e8b92781c4 Use transaction when favoriting to prevent post from being half-favorited 2014-04-11 14:50:34 -04:00
r888888888
48ae3bcefd fixes #2116 2014-03-27 15:29:16 -07:00
Toks
4c520c1d16 fix score seeming to increase for member favoriting 2013-06-11 09:38:15 -04:00
r888888888
61f8c38d34 fixes #952 2013-06-10 18:12:57 -07:00
r888888888
7db85d8301 Merge branch 'master' into close-accounts 2013-05-16 14:16:47 -07:00
r888888888
8ba43c8cd1 fix regression with tag post counts 2013-05-06 18:15:27 -07:00
r888888888
890e11f532 potential fix for #1500 2013-05-06 13:33:04 -07:00
r888888888
51a62a8df6 add support for deleting user accounts 2013-04-29 22:47:08 -07:00
r888888888
d5f575159f rename references of privileged to gold 2013-04-28 00:04:52 -07:00
r888888888
00034f1a17 refactored favorites 2013-04-18 20:19:11 -07:00
小太
cba839ba76 Kill trailing whitespace in ruby files 2013-03-19 23:10:10 +11:00
albert
073ab8ee96 * Fixed favorites deletion
* Fixed parenting when dealing with post deletion
2012-01-06 18:20:18 -05:00
albert
cce3fe0b64 added constraint for fav search 2011-11-16 13:12:02 -05:00
albert
e42ea9c608 added popular exploration, added order:rank 2011-08-11 15:39:51 -04:00
albert
469ae14805 fixed tests, implemented sql based partitioning for favorites 2011-07-16 20:16:34 -04:00
albert
2f1fdcb459 more work on paginators 2011-06-21 14:32:07 -04:00
albert
f67374da83 * Some major bug fixes related to post sets. Tests for pools and favorites were added.
* Refactored the favorites code a bit. Adding a favorite from either an user or a post now works and will update all necessary records.
2011-06-07 19:06:39 -04:00
albert
49b3d43ddd * meta_search now pulls directly from GitHub
* Updated gems
* [inprogress] New pagination helpers used instead of pagination presenters
* [inprogress] Favorites refactored to use ActiveRecord
* [inprogress] PostSets refactored to use a decorator/dependency injection pattern
* [inprogress] Made pool/post interaction more robust
* Pool#posts now returns an ActiveRelation object
* Fixed unit tests
2011-06-07 17:34:09 -04:00
albert
435d3bf6e2 fixed user tests 2011-06-05 04:05:21 -04:00