Top posts test
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / Libvips tests (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (push) Blocked by required conditions
Ruby Testing / Back to original and return test (push) Blocked by required conditions

This commit is contained in:
Mario 2025-06-12 20:00:16 -04:00
parent 725811a2e3
commit 16a2f4fb9e
8 changed files with 90 additions and 2 deletions

View file

@ -0,0 +1,10 @@
module Api::V1::Timelines
class LocalTopController < ApiController
before_action :require_user!
def show
@statuses = LocalTopPostsService.new.call
render json: @statuses
end
end
end

View file

@ -1,6 +1,16 @@
import Trends from 'mastodon/features/getting_started/containers/trends_container';
import { showTrends } from 'mastodon/initial_state';
import { Link } from 'react-router-dom';
export const NavigationPortal: React.FC = () => (
<div className='navigation-panel__portal'>{showTrends && <Trends />}</div>
);
<div className='navigation-panel__portal'>
{/* Existing Trends section */}
{showTrends && <Trends />}
{/* Add Local Top tab */}
<Link to='/timelines/local_top' className='column-link'>
<i className='fa fa-fire' />
<span>Local Top</span>
</Link>
</div>
);

View file

@ -0,0 +1,14 @@
// app/javascript/mastodon/features/local_top_timeline/index.js
import React from 'react';
import Timeline from '../../components/timeline';
export default class LocalTopTimeline extends React.PureComponent {
render() {
return (
<Timeline
endpoint='/api/v1/timelines/local_top'
{...this.props}
/>
);
}
}

View file

@ -0,0 +1,6 @@
// app/javascript/mastodon/routes.js
{
path: '/timelines/local_top',
component: AsyncComponent(() => import('../features/local_top_timeline')),
exact: true,
}

View file

@ -0,0 +1,15 @@
class LocalTopPostsService < BaseService
# Rank local posts by engagement (boosts > favs > replies) in last 24h
def call
Status
.local
.joins(:status_stat)
.where('statuses.created_at > ?', 24.hours.ago)
.select('statuses.*,
(status_stats.reblogs_count * 0.6 +
status_stats.favourites_count * 0.3 +
status_stats.replies_count * 0.1) AS engagement_score')
.order('engagement_score DESC')
.limit(50) # Adjust as needed
end
end

View file

@ -21,3 +21,13 @@ class PrecomputeFeedService < BaseService
@skip_filled_timelines && FeedManager.instance.timeline_size(type, id) * 2 > FeedManager::MAX_ITEMS
end
end
# app/services/precompute_feed_service.rb
def call(user)
case user.feed_algorithm
when 'local_top'
LocalTopPostsService.new.call
else
Status.chronological # Default
end
end

View file

@ -163,6 +163,17 @@ Rails.application.routes.draw do
resources :statuses, only: :show
end
# config/routes.rb
namespace :api do
namespace :v1 do
resources :timelines do
collection do
get :local_top
end
end
end
end
resources :media, only: [:show] do
get :player
end

View file

@ -0,0 +1,12 @@
# db/migrate/20240612000000_add_local_top_algorithm_support.rb
class AddLocalTopAlgorithmSupport < ActiveRecord::Migration[6.1]
def change
# Ensure status_stats exists (Mastodon usually has this)
unless column_exists?(:statuses, :status_stat_id)
add_reference :statuses, :status_stat, foreign_key: { on_delete: :cascade }
end
# Add user preference for feed algorithm (default: chronological)
add_column :users, :feed_algorithm, :string, default: 'chronological'
end
end