Skip to content

Expose image subscriptions similar to hides (#527).#684

Open
luckydonald wants to merge 1 commit into
philomena-dev:masterfrom
luckydonald-forks:feature/subscription-count
Open

Expose image subscriptions similar to hides (#527).#684
luckydonald wants to merge 1 commit into
philomena-dev:masterfrom
luckydonald-forks:feature/subscription-count

Conversation

@luckydonald
Copy link
Copy Markdown
Contributor

@luckydonald luckydonald commented May 1, 2026

As the count of hides of an image are provided,
similar shall be the (comment-)subscription count.

This is based on the changes for hides in ba90478 (know as eef9ec6 after rebase).


My


Changes made:

  1. Migration: adds subscriptions_count integer not null default 0 to images and backfills it from image_subscriptions.
  2. image.ex: added field :subscriptions_count, :integer, default: 0.
  3. 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. 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. search_index.ex: added subscriptions: %{type: "integer"} to the mapping and subscriptions: image.subscriptions_count to as_json/1.
  6. query.ex: added subscriptions to int_fields in anonymous_fields/0.
  7. image_sorter.ex: added subscriptions to @allowed_fields.
  8. _form.html.slime: added "Sort by subscriptions": :subscriptions after the hides entry.
  9. json/image_view.ex: added subscriptions: image.subscriptions_count to the image JSON response.

Before you begin

  • I understand my contributions may be rejected for any reason
  • I understand my contributions are for the benefit of Derpibooru and/or the Philomena software
  • I understand my contributions are licensed under the GNU AGPLv3
  • I understand all of the above

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.
@liamwhite
Copy link
Copy Markdown
Contributor

What benefit does exposing the subscription count have?

@luckydonald
Copy link
Copy Markdown
Contributor Author

@liamwhite Mostly symmetry to the hides, while I worked on #685.

@Meow
Copy link
Copy Markdown
Member

Meow commented May 2, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants