-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #5578
- Loading branch information
Showing
22 changed files
with
444 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
class DirectoriesController < ApplicationController | ||
layout 'public' | ||
|
||
before_action :set_instance_presenter | ||
before_action :set_tag, only: :show | ||
before_action :set_tags | ||
before_action :set_accounts | ||
|
||
def index | ||
render :index | ||
end | ||
|
||
def show | ||
render :index | ||
end | ||
|
||
private | ||
|
||
def set_tag | ||
@tag = Tag.find_by!(name: params[:id].downcase) | ||
end | ||
|
||
def set_tags | ||
@tags = Tag.joins(:account_tag_stat).where('accounts_count > 0').order(name: :asc).limit(30) | ||
end | ||
|
||
def set_accounts | ||
@accounts = Account.searchable.discoverable.page(params[:page]).per(50).tap do |query| | ||
query.merge!(Account.tagged_with(@tag.id)) if @tag | ||
|
||
if popular_requested? | ||
query.merge!(Account.popular) | ||
else | ||
query.merge!(Account.by_recent_status) | ||
end | ||
end | ||
end | ||
|
||
def set_instance_presenter | ||
@instance_presenter = InstancePresenter.new | ||
end | ||
|
||
def popular_requested? | ||
request.path.ends_with?('/popular') | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
# == Schema Information | ||
# | ||
# Table name: account_tag_stats | ||
# | ||
# id :bigint(8) not null, primary key | ||
# tag_id :bigint(8) not null | ||
# accounts_count :bigint(8) default(0), not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class AccountTagStat < ApplicationRecord | ||
belongs_to :tag, inverse_of: :account_tag_stat | ||
|
||
def increment_count!(key) | ||
update(key => public_send(key) + 1) | ||
end | ||
|
||
def decrement_count!(key) | ||
update(key => [public_send(key) - 1, 0].max) | ||
end | ||
end |
This file contains 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
This file contains 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
Oops, something went wrong.