about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-18 19:54:23 +0100
committerGitHub <noreply@github.com>2019-03-18 19:54:23 +0100
commitb9a998f201913dd1c89ddcb0c4c9e181eb73bfcf (patch)
tree2d5705651ce83b73900ff3e2ce61d8fef1c1b25d /app/controllers
parent6e3a4bcbc70bb33bfb0746cf3b2186ee9f4e6515 (diff)
parent841b920af5de8e3188111ca4dbea0c5105bde88c (diff)
Merge pull request #963 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/accounts_controller.rb8
-rw-r--r--app/controllers/application_controller.rb5
-rw-r--r--app/controllers/follower_accounts_controller.rb1
-rw-r--r--app/controllers/relationships_controller.rb19
-rw-r--r--app/controllers/statuses_controller.rb4
5 files changed, 28 insertions, 9 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 157ea8569..fcdebb47f 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -11,6 +11,8 @@ class AccountsController < ApplicationController
     respond_to do |format|
       format.html do
         use_pack 'public'
+        mark_cacheable! unless user_signed_in?
+
         @body_classes      = 'with-modals'
         @pinned_statuses   = []
         @endorsed_accounts = @account.endorsed_accounts.to_a.sample(4)
@@ -31,17 +33,21 @@ class AccountsController < ApplicationController
       end
 
       format.atom do
+        mark_cacheable!
+
         @entries = @account.stream_entries.where(hidden: false).with_includes.paginate_by_max_id(PAGE_SIZE, params[:max_id], params[:since_id])
         render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.feed(@account, @entries.reject { |entry| entry.status.nil? || entry.status.local_only? }))
       end
 
       format.rss do
+        mark_cacheable!
+
         @statuses = cache_collection(default_statuses.without_reblogs.without_replies.limit(PAGE_SIZE), Status)
         render xml: RSS::AccountSerializer.render(@account, @statuses)
       end
 
       format.json do
-        skip_session!
+        mark_cacheable!
 
         render_cached_json(['activitypub', 'actor', @account], content_type: 'application/activity+json') do
           ActiveModelSerializers::SerializableResource.new(@account, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0209805d0..5401b9d59 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -227,6 +227,11 @@ class ApplicationController < ActionController::Base
     response.headers['Vary'] = 'Accept'
   end
 
+  def mark_cacheable!
+    skip_session!
+    expires_in 0, public: true
+  end
+
   def skip_session!
     request.session_options[:skip] = true
   end
diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb
index f985f0eff..213c209ab 100644
--- a/app/controllers/follower_accounts_controller.rb
+++ b/app/controllers/follower_accounts_controller.rb
@@ -7,6 +7,7 @@ class FollowerAccountsController < ApplicationController
     respond_to do |format|
       format.html do
         use_pack 'public'
+        mark_cacheable! unless user_signed_in?
 
         next if @account.user_hides_network?
 
diff --git a/app/controllers/relationships_controller.rb b/app/controllers/relationships_controller.rb
index af91cb658..a0b9c77df 100644
--- a/app/controllers/relationships_controller.rb
+++ b/app/controllers/relationships_controller.rb
@@ -32,17 +32,18 @@ class RelationshipsController < ApplicationController
   def relationships_scope
     scope = begin
       if following_relationship?
-        current_account.following.includes(:account_stat)
+        current_account.following.joins(:account_stat)
       else
-        current_account.followers.includes(:account_stat)
+        current_account.followers.joins(:account_stat)
       end
     end
 
     scope.merge!(Follow.recent)
     scope.merge!(mutual_relationship_scope) if mutual_relationship?
-    scope.merge!(abandoned_account_scope)   if params[:status] == 'abandoned'
-    scope.merge!(active_account_scope)      if params[:status] == 'active'
+    scope.merge!(moved_account_scope)       if params[:status] == 'moved'
+    scope.merge!(primary_account_scope)     if params[:status] == 'primary'
     scope.merge!(by_domain_scope)           if params[:by_domain].present?
+    scope.merge!(dormant_account_scope)     if params[:activity] == 'dormant'
 
     scope
   end
@@ -51,14 +52,18 @@ class RelationshipsController < ApplicationController
     Account.where(id: current_account.following)
   end
 
-  def abandoned_account_scope
+  def moved_account_scope
     Account.where.not(moved_to_account_id: nil)
   end
 
-  def active_account_scope
+  def primary_account_scope
     Account.where(moved_to_account_id: nil)
   end
 
+  def dormant_account_scope
+    AccountStat.where(last_status_at: nil).or(AccountStat.where(AccountStat.arel_table[:last_status_at].lt(1.month.ago)))
+  end
+
   def by_domain_scope
     Account.where(domain: params[:by_domain])
   end
@@ -80,7 +85,7 @@ class RelationshipsController < ApplicationController
   end
 
   def current_params
-    params.slice(:page, :status, :relationship, :by_domain).permit(:page, :status, :relationship, :by_domain)
+    params.slice(:page, :status, :relationship, :by_domain, :activity).permit(:page, :status, :relationship, :by_domain, :activity)
   end
 
   def action_from_button
diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb
index 6f56a67ba..53cf1c4ca 100644
--- a/app/controllers/statuses_controller.rb
+++ b/app/controllers/statuses_controller.rb
@@ -28,6 +28,8 @@ class StatusesController < ApplicationController
     respond_to do |format|
       format.html do
         use_pack 'public'
+        mark_cacheable! unless user_signed_in?
+
         @body_classes = 'with-modals'
 
         set_ancestors
@@ -37,7 +39,7 @@ class StatusesController < ApplicationController
       end
 
       format.json do
-        skip_session! unless @stream_entry.hidden?
+        mark_cacheable! unless @stream_entry.hidden?
 
         render_cached_json(['activitypub', 'note', @status], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
           ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter)