Expose image subscriptions similar to hides (#527).#684
Open
luckydonald wants to merge 1 commit into
Open
Conversation
This is based on the changes for `hides` in ba90478 (know as eef9ec6 after rebase). Changes made: 1. Migration (`priv/repo/migrations/20260501234567_add_subscriptions_count_to_images.exs`) — adds `subscriptions_count integer not null default 0` to images and backfills it from `image_subscriptions`. 2. `lib/philomena/images/image.ex` — added `field :subscriptions_count, :integer, default: 0`. 3. `lib/philomena/subscriptions.ex` — added `defoverridable create_subscription: 2, delete_subscription: 2` at the end of the `quote` block so callers can override with `super/2`. 4. `lib/philomena/images.ex` — added `create_subscription/2` and `delete_subscription/2` overrides that call `super` then increment/decrement `subscriptions_count` atomically via `Repo.update_all(inc: ...)`. 5. `lib/philomena/images/search_index.ex` — added `subscriptions: %{type: "integer"}` to the mapping and `subscriptions: image.subscriptions_count` to `as_json/1`. 6. `lib/philomena/images/query.ex` — added `subscriptions` to `int_fields` in `anonymous_fields/0`. 7. `lib/philomena_web/image_sorter.ex` — added `subscriptions` to `@allowed_fields`. 8. `lib/philomena_web/templates/search/_form.html.slime` — added `"Sort by subscriptions": :subscriptions` after the `hides` entry. 9. `lib/philomena_web/views/api/json/image_view.ex` — added `subscriptions: image.subscriptions_count` to the image JSON response.
Contributor
|
What benefit does exposing the subscription count have? |
Contributor
Author
|
@liamwhite Mostly symmetry to the |
Member
|
I'll discuss this change with the booru mod team. They're ultimately the ones who decide what goes policy-wise, and exposing an extra number seems like a policy decision. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As the count of hides of an image are provided,
similar shall be the (comment-)subscription count.
This is based on the changes for
hidesin ba90478 (know as eef9ec6 after rebase).My
Changes made:
subscriptions_count integer not null default 0to images and backfills it fromimage_subscriptions.image.ex: addedfield :subscriptions_count, :integer, default: 0.subscriptions.ex: addeddefoverridable create_subscription: 2, delete_subscription: 2at the end of thequoteblock so callers can override withsuper/2.philomena/images.ex: addedcreate_subscription/2anddelete_subscription/2overrides that callsuperthen increment/decrementsubscriptions_countatomically viaRepo.update_all(inc: ...).search_index.ex: addedsubscriptions: %{type: "integer"}to the mapping andsubscriptions: image.subscriptions_counttoas_json/1.query.ex: addedsubscriptionstoint_fieldsinanonymous_fields/0.image_sorter.ex: addedsubscriptionsto@allowed_fields._form.html.slime: added"Sort by subscriptions": :subscriptionsafter thehidesentry.json/image_view.ex: addedsubscriptions: image.subscriptions_countto the image JSON response.Before you begin