source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/filter_parameter_logging.rb | Ruby | apache-2.0 | 187 | the-future | 207 | # Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += %i[password token email] |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/inflections.rb | Ruby | apache-2.0 | 187 | the-future | 422 | # frozen_string_literal: true
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.uncountable %w[anime manga media anime_staff manga_staff drama_staff media_staff]
inflect.acronym 'DSL'
inflect.acronym 'HTML'
inflect.acronym 'XML'
inflect.acronym 'SSO'
inflect.acronym 'STI'
inflect.acronym 'AM... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/deprecation_subscriber.rb | Ruby | apache-2.0 | 187 | the-future | 685 | # frozen_string_literal: true
class DeprecationSubscriber < ActiveSupport::Subscriber
class DisallowedDeprecation < StandardError; end
module RubyWarningSubscriber
def warn(message, category: nil, **_kwargs)
if category == :deprecated
ActiveSupport::Deprecation.warn(message)
else
s... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/rails_admin.rb | Ruby | apache-2.0 | 187 | the-future | 16,058 | # frozen_string_literal: true
require Rails.root.join('lib/rails_admin/config/fields/types/localized_string')
require Rails.root.join('lib/rails_admin/config/fields/types/localized_text')
require Rails.root.join('lib/rails_admin/config/fields/types/string_list')
require Rails.root.join('lib/rails_admin/config/fields/t... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/00_prometheus_exporter.rb | Ruby | apache-2.0 | 187 | the-future | 408 | # frozen_string_literal: true
require 'prometheus_exporter/client'
require 'prometheus_exporter/middleware'
Rails.application.middleware.unshift PrometheusExporter::Middleware
if Rails.env.development? || Rails.env.test?
class NullClient < PrometheusExporter::Client
def send(*); end
end
PrometheusExporter... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/sidekiq.rb | Ruby | apache-2.0 | 187 | the-future | 1,648 | # frozen_string_literal: true
require 'sidekiq/middleware/server/chewy'
require 'sidekiq/middleware/server/current_user'
require 'sidekiq/middleware/server/stream_buffer_flusher'
require 'sidekiq/middleware/client/current_user'
Sidekiq.default_job_options = { queue: 'later' }
Sidekiq.configure_server do |config|
r... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/doorkeeper.rb | Ruby | apache-2.0 | 187 | the-future | 2,896 | # frozen_string_literal: true
require 'authorization/assertion/facebook'
require 'authorization/password'
Doorkeeper.configure do
orm :active_record
# HACK: this idiocy is O(n) so try to avoid choking the database
token_lookup_batch_size 500
# => Authentication
# Check whether the resource owner is authent... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/shrine.rb | Ruby | apache-2.0 | 187 | the-future | 2,020 | require 'shrine/storage/s3'
Shrine.plugin :activerecord
Shrine.plugin :pretty_location
# We upload in the most cursed fashion
Shrine.plugin :data_uri
# MIME is Hard
Shrine.plugin :determine_mime_type, analyzer: :marcel
Shrine.plugin :infer_extension
# Handle derivatives in background
Shrine.plugin :derivatives
Shrine.... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/chewy.rb | Ruby | apache-2.0 | 187 | the-future | 312 | # frozen_string_literal: true
Chewy.settings = {
sidekiq: {
queue: 'later'
},
transport_options: {
request: {
open_timeout: 10,
timeout: 15
}
}
}
if ENV['CHEWY_STRATEGY']
Chewy.strategy(ENV['CHEWY_STRATEGY'].to_sym)
Chewy.request_strategy = ENV['CHEWY_STRATEGY'].to_sym
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/sentry-ruby.rb | Ruby | apache-2.0 | 187 | the-future | 577 | # frozen_string_literal: true
Sentry.init do |config|
config.release = Rails.root.join('.version').read.strip if Rails.root.join('.version').exist?
config.traces_sample_rate = 1.0
config.profiles_sample_rate = 1.0
config.breadcrumbs_logger = %i[sentry_logger http_logger active_support_logger]
config.excluded... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/flipper.rb | Ruby | apache-2.0 | 187 | the-future | 503 | require 'flipper/adapters/redis'
Flipper.configure do |config|
config.default do
# Connect to Redis and initialize Flipper
adapter = Flipper::Adapters::Redis.new(Redis.new)
Flipper.new(adapter)
end
end
Flipper.register(:staff) do |user|
user&.permissions&.admin?
end
Flipper.register(:pro) do |user|... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/rack-attack.rb | Ruby | apache-2.0 | 187 | the-future | 1,155 | # frozen_string_literal: true
class Rack::Attack
throttle('logins/ip', limit: 15, period: 60.seconds) do |req|
if req.path == '/api/oauth/token' && req.post? && req.params['grant_type'] == 'password'
ActionDispatch::Request.new(req.env).remote_ip
end
end
throttle('registrations/ip', limit: 5, peri... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/jsonapi-resources.rb | Ruby | apache-2.0 | 187 | the-future | 1,955 | # frozen_string_literal: true
require Rails.root.join('vendor/resource_serializer')
require Rails.root.join('lib/instrumented_processor')
JSONAPI_RESOURCES_CACHE_HITS_TOTAL = $prometheus.register(
:counter,
'jsonapi_resources_cache_hits_total',
'Number of cache hits for JSONAPI::Resources'
)
JSONAPI_RESOURCES_... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/secret_token.rb | Ruby | apache-2.0 | 187 | the-future | 968 | # Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary atta... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/rolify.rb | Ruby | apache-2.0 | 187 | the-future | 249 | Rolify.configure do |config|
# By default ORM adapter is ActiveRecord. uncomment to use mongoid
# config.use_mongoid
# Dynamic shortcuts for User class (user.is_admin? like methods).
# Default is: false
# config.use_dynamic_shortcuts
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/marginalia.rb | Ruby | apache-2.0 | 187 | the-future | 241 | require 'marginalia'
module Marginalia::Comment
def self.request_path
marginalia_controller.request.fullpath
rescue StandardError
nil
end
end
Marginalia::Comment.components = %i[request_path controller_with_namespace action] |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/stream_rails.rb | Ruby | apache-2.0 | 187 | the-future | 915 | # Feeds:
# user/2 (flat) - Posts made by user/2
# user_aggr/2 (aggregated) - Follows user by id for display
# media/anime:8932 (flat) - Gets CC'd posts related to the media
# media_aggr/anime:8932 (aggregated) - Follows media feed by id for display
# group/1234 (flat) - Posts made in group/1234
# group_aggr... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/initializers/html-pipeline.rb | Ruby | apache-2.0 | 187 | the-future | 228 | HTML::Pipeline.class_eval do
def self.parse(document_or_html)
document_or_html ||= ''
if document_or_html.is_a?(String)
Nokogiri::HTML.fragment(document_or_html)
else
document_or_html
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/environments/staging.rb | Ruby | apache-2.0 | 187 | the-future | 2,797 | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, a... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/environments/test.rb | Ruby | apache-2.0 | 187 | the-future | 2,619 | # frozen_string_literal: true
require 'active_support/core_ext/integer/time'
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test r... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/environments/production.rb | Ruby | apache-2.0 | 187 | the-future | 4,357 | # frozen_string_literal: true
require 'active_support/core_ext/integer/time'
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads mos... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | config/environments/development.rb | Ruby | apache-2.0 | 187 | the-future | 2,609 | # frozen_string_literal: true
require 'active_support/core_ext/integer/time'
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded any time
# it changes. This slows down response ti... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/action.rb | Ruby | apache-2.0 | 187 | the-future | 2,174 | # An Action is a class representing a single task. It's an implementation of the "command" pattern,
# comparable to the Interactors gem. Unlike Interactors, however, Actions are based on ActiveModel,
# and are expected to raise an exception when they fail.
#
# == Why Not Interactors?
#
# Interactors implement a monad... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/with_progress_bar.rb | Ruby | apache-2.0 | 187 | the-future | 663 | # Handy dandy mixin for providing a progress bar shortcut with our default format!
module WithProgressBar
extend ActiveSupport::Concern
class_methods do
# Shortcut to generating a new progress bar object
#
# @param title [String] the label to be displayed for the progress bar
# @param count [Intege... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/library_paginator.rb | Ruby | apache-2.0 | 187 | the-future | 447 | class LibraryPaginator < OffsetPaginator
private
def verify_pagination_params
if @limit < 1
raise JSONAPI::Exceptions::InvalidPageValue.new(:limit, @limit)
end
if @limit > 500
raise JSONAPI::Exceptions::InvalidPageValue.new(:limit, @limit,
detail: 'Limit exceeds maximum page size o... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/instrumented_processor.rb | Ruby | apache-2.0 | 187 | the-future | 636 | class InstrumentedProcessor < JSONAPI::Processor
%i[
operation find show show_relationship show_related_resource show_related_resources
create_resource remove_resource replace_fields replace_to_one_relationship
create_to_many_relationships replace_to_many_relationships remove_to_many_relationships
rem... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/dirty_change_wrapper.rb | Ruby | apache-2.0 | 187 | the-future | 790 | class DirtyChangeWrapper < SimpleDelegator
def initialize(base, changes)
super(base)
@changes = changes
changes.each do |key, (before, after)|
define_singleton_method(key) { after }
define_singleton_method("#{key}_was") { before }
define_singleton_method("#{key}_changed?") { true }
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/admin_constraint.rb | Ruby | apache-2.0 | 187 | the-future | 255 | class AdminConstraint
def self.matches?(request)
return false unless request.session[:token]
token = Doorkeeper::AccessToken.by_token(request.session[:token])
user = User.find(token[:resource_owner_id])
user&.permissions&.any?
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/postgres_sequence_fixer.rb | Ruby | apache-2.0 | 187 | the-future | 1,080 | class PostgresSequenceFixer
def self.run
sequences.each { |s| new(s).run }
end
def self.sequences
execute(<<-SQL).values.flatten
SELECT relname
FROM pg_class
WHERE relkind = 'S'
SQL
end
def initialize(sequence_name)
@sequence_name = sequence_name
end
def run
execut... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/seed_file.rb | Ruby | apache-2.0 | 187 | the-future | 1,126 | # frozen_string_literal: true
class SeedFile
MAX_ID = 2_147_483_647 # Yoinked from Postgres docs
attr_reader :model, :file
def initialize(file, model: nil)
@file = file
@model = model || File.basename(file, '.*').classify.constantize
end
def import!
data.map do |label, row_data|
# ruboco... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/unlimited_paginator.rb | Ruby | apache-2.0 | 187 | the-future | 571 | # I am the bone of my paginator
# Steel is my body and fire is my blood
# I have created over a thousand pages
# Unknown to Death, Nor known to Life
# Have withstood pain to create many pages
# Yet, those hands will never hold anything
# So as I pray, unlimited pagination works
class UnlimitedPaginator < OffsetPaginat... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/image_info.rb | Ruby | apache-2.0 | 187 | the-future | 361 | # frozen_string_literal: true
class ImageInfo
def initialize(file_path)
@file_path = file_path
end
def type
if fastimage.type == :png && animated?
:apng
else
fastimage.type
end
end
def animated?
FastImage.animated?(@file_path)
end
private
def fastimage
@fastimage... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/update_in_batches.rb | Ruby | apache-2.0 | 187 | the-future | 1,189 | # frozen_string_literal: true
module UpdateInBatches
# rubocop:disable all
refine ActiveRecord::Relation do
def update_in_batches(updates = {}, of: 10000, **kwargs)
updates = updates.merge(kwargs) if updates.is_a?(Hash)
relation = self
relation = relation.reorder(batch_order).limit(of)
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/universal_paginator.rb | Ruby | apache-2.0 | 187 | the-future | 1,060 | # frozen_string_literal: true
class UniversalPaginator < JSONAPI::Paginator
attr_reader :params
def initialize(params)
super
@params = params
# Initialize sub-paginator
paginator
end
def offset?
if params&.fetch(:offset, nil) || params&.fetch(:limit, nil)
true
else
false
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/stream_log.rb | Ruby | apache-2.0 | 187 | the-future | 1,931 | module StreamLog
module_function
def follow(source, target)
return false unless ENV['STREAMLOG_REDIS_URL']
return unless log_follow?(source, target)
source = rewrite_feed(*source)
target = rewrite_feed(*target)
return unless source && target
follow = follow_key(source, target)
redis_poo... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/counter_cache_resets.rb | Ruby | apache-2.0 | 187 | the-future | 7,813 | # frozen_string_literal: true
module CounterCacheResets
module_function
def posts
execute sql_for(Post, :post_likes)
execute sql_for(Post, :comments)
execute sql_for(Post, :comments,
counter_cache_column: 'top_level_comments_count',
where: 'parent_id IS NULL')
end
def media_user_count... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/buffered_stream_client.rb | Ruby | apache-2.0 | 187 | the-future | 2,480 | # This class is wrapper for {Stream::Client} which provides buffering of actions to be executed en
# masse using Stream's bulk APIs. For example, if a single request makes multiple follow requests,
# we can bundle those up into a single hit to the Stream API and thus make execution more efficient.
# Of course, as with... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/sidekiq/middleware/server/current_user.rb | Ruby | apache-2.0 | 187 | the-future | 582 | # frozen_string_literal: true
module Sidekiq
module Middleware
module Server
class CurrentUser
def call(_, job, _)
# Extract the User ID from job metadata
user = User.find_by(id: job['current_user'])
# Save it onto the thread
Thread.current[:current_user] = u... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/sidekiq/middleware/server/chewy.rb | Ruby | apache-2.0 | 187 | the-future | 202 | module Sidekiq
module Middleware
module Server
class Chewy
def call(*)
::Chewy.strategy(:atomic) do
yield
end
end
end
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/sidekiq/middleware/server/stream_buffer_flusher.rb | Ruby | apache-2.0 | 187 | the-future | 216 | module Sidekiq
module Middleware
module Server
class StreamBufferFlusher
def call(*)
yield
ensure
Feed.client.try(:flush_async)
end
end
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/sidekiq/middleware/client/current_user.rb | Ruby | apache-2.0 | 187 | the-future | 210 | module Sidekiq
module Middleware
module Client
class CurrentUser
def call(_, job, *)
job['current_user'] = User.current&.id
yield
end
end
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/rails_admin/config/fields/types/localized_string.rb | Ruby | apache-2.0 | 187 | the-future | 1,196 | require 'rails_admin/config/fields/types/text'
module RailsAdmin
module Config
module Fields
module Types
class LocalizedString < RailsAdmin::Config::Fields::Types::Text
# Register field type for the type loader
RailsAdmin::Config::Fields::Types.register(self)
registe... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/rails_admin/config/fields/types/duration.rb | Ruby | apache-2.0 | 187 | the-future | 1,713 | require 'rails_admin/config/fields/types/string'
module RailsAdmin
module Config
module Fields
module Types
class Duration < RailsAdmin::Config::Fields::Types::String
# Register field type for the type loader
RailsAdmin::Config::Fields::Types.register(self)
STR_TO_UNI... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/rails_admin/config/fields/types/localized_text.rb | Ruby | apache-2.0 | 187 | the-future | 1,397 | require 'rails_admin/config/fields/types/text'
module RailsAdmin
module Config
module Fields
module Types
class LocalizedText < RailsAdmin::Config::Fields::Types::Text
# Register field type for the type loader
RailsAdmin::Config::Fields::Types.register(self)
register_... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/rails_admin/config/fields/types/string_list.rb | Ruby | apache-2.0 | 187 | the-future | 1,044 | require 'rails_admin/config/fields/types/text'
module RailsAdmin
module Config
module Fields
module Types
class StringList < RailsAdmin::Config::Fields::Types::Text
# Register field type for the type loader
RailsAdmin::Config::Fields::Types.register(self)
register_ins... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/rails_admin/config/fields/types/flags.rb | Ruby | apache-2.0 | 187 | the-future | 882 | module RailsAdmin
module Config
module Fields
module Types
class Flags < RailsAdmin::Config::Fields::Base
RailsAdmin::Config::Fields::Types.register(self)
def value
bindings[:object].public_send(name)
end
def generic_help
''
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/tasks/graphql.rake | Ruby | apache-2.0 | 187 | the-future | 364 | namespace :graphql do
task dump_schema: :environment do
require 'graphql/rake_task'
GraphQL::RakeTask.new(
load_schema: ->(_task) {
require File.expand_path('../../app/graphql/kitsu_schema', __dir__)
KitsuSchema
},
directory: './' # Creates ./schema.graphql
)
Rake::... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/tasks/stats.rake | Ruby | apache-2.0 | 187 | the-future | 390 | task :stats => "kitsu:stats_setup"
namespace :kitsu do
task :stats_setup do
require 'rails/code_statistics'
::STATS_DIRECTORIES += {
'Indices' => 'app/chewy',
'Workers' => 'app/workers',
'Resources' => 'app/resources',
'Services' => 'app/services',
'Policies' => 'app/policies'
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/tasks/user_stats.rake | Ruby | apache-2.0 | 187 | the-future | 461 | namespace :kitsu do
task user_stats: :environment do
klass = RegenerateStatService
# Category Breakdown
klass.anime_category_breakdown
klass.manga_category_breakdown
# Amount Watched/Read
klass.anime_amount_consumed
klass.manga_amount_consumed
# Favorite Year
klass.anime_favorit... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/tasks/counters.rake | Ruby | apache-2.0 | 187 | the-future | 298 | namespace :counters do
desc 'Update all counter caches'
task :fix => :environment do
CounterCacheResets.posts
CounterCacheResets.media_user_counts
CounterCacheResets.reviews
CounterCacheResets.users
CounterCacheResets.groups
CounterCacheResets.category_counts
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/buffered_stream_client/buffered_feed.rb | Ruby | apache-2.0 | 187 | the-future | 2,123 | class BufferedStreamClient
class BufferedFeed
# @private
delegate :duration, to: BufferedStreamClient
# @api getstream-compat
delegate :readonly_token, to: :@feed
delegate :get, to: :@feed
delegate :following, to: :@feed
delegate :followers, to: :@feed
# @private
# @param group [... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/buffered_stream_client/action_buffer.rb | Ruby | apache-2.0 | 187 | the-future | 1,241 | class BufferedStreamClient
# A class for wrapping the buffering of actions to be executed by the client
class ActionBuffer
# @param queue [Hash] the queue data to preload
def initialize(queue = Hash.new { [] })
@queue = queue
end
# Add something to the queue
#
# @param key [Object] th... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/buffered_stream_client/unfollow_buffer.rb | Ruby | apache-2.0 | 187 | the-future | 1,353 | # frozen_string_literal: true
class BufferedStreamClient
class UnfollowBuffer < RedisBuffer
# The numbers below are slightly below the max rate limit just for safety
# We can send 250 unfollow requests per 60 seconds
RATE_LIMIT = 240 / 60 * 5
# Match a valid feed name
VALID_FEED = /\A[\w-]+:[\w-]... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/buffered_stream_client/redis_buffer.rb | Ruby | apache-2.0 | 187 | the-future | 3,879 | class BufferedStreamClient
# A system for buffering actions to be sent in groups to Stream's API. This can be used for
# anything which is batchable, even if the batches have to be grouped by a sub-key (for example,
# follows need to be sent in batches grouped by the size of the scrollback). For things which
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/buffered_stream_client/follow_buffer.rb | Ruby | apache-2.0 | 187 | the-future | 1,617 | # frozen_string_literal: true
class BufferedStreamClient
class FollowBuffer < RedisBuffer
# The numbers below are slightly below the max rate limit just for safety
# We flush 3 queues per batch
GROUPS_PER_BATCH = 2
# We can send 250 follow-many requests per 60 seconds
RATE_LIMIT = 60.seconds / 24... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/buffered_stream_client/activity_buffer.rb | Ruby | apache-2.0 | 187 | the-future | 790 | class BufferedStreamClient
class ActivityBuffer < ActionBuffer
BULK_THRESHOLD = 2
def push(key, *items)
key = key.stream_id if key.respond_to?(:stream_id)
super(key, *items)
end
def flush(client)
reset.tap do |queue|
# Iterate over each feed and submit the activities for it... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/action/dsl.rb | Ruby | apache-2.0 | 187 | the-future | 1,151 | class Action
module DSL
extend ActiveSupport::Concern
included do
class_attribute :attribute_names
end
class_methods do
# @param key [#to_s] the key to set up as a parameter
# @param cast [Proc,nil] a function to convert an input object before calling
# @param load [.find] an... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/action/validation_error.rb | Ruby | apache-2.0 | 187 | the-future | 244 | class Action
# RAILS-5: remove own validate! and replace with ActiveModel#validate!
class ValidationError < StandardError
attr_reader :model
def initialize(model)
@model = model
super('Model invalid')
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/media_attributes_import/seed_attributes.rb | Ruby | apache-2.0 | 187 | the-future | 2,219 | module MediaAttributesImport
class SeedAttributes
def initialize
@init_attributes = %w[Pacing Complexity Tone]
@init_attributes_titles = {
'Pacing' => {
'low' => 'Slow',
'neutral' => 'Neutral',
'high' => 'Fast'
},
'Complexity' => {
'low' ... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/stream/log_subscriber.rb | Ruby | apache-2.0 | 187 | the-future | 1,452 | module Stream
class LogSubscriber < ActiveSupport::LogSubscriber
def follow(event)
return unless logger.debug?
payload = event.payload
name = format_name('Follow', event.duration, CYAN)
debug " #{name} #{format_follows(payload[:source], payload[:target])}"
end
def unfollow(event... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/anidb_category_import/media_importer.rb | Ruby | apache-2.0 | 187 | the-future | 2,821 | class MediaImporter
class ImportFile
attr_reader :data
def initialize(base_media_url, anime_assoc_file, genre_map_file)
# Loading the JSON
utc = Time.now.to_i.to_s
anime_json_file = open(
base_media_url +
anime_assoc_file +
'?' +
utc
).read
@data ... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/anidb_category_import/category_importer.rb | Ruby | apache-2.0 | 187 | the-future | 1,251 | class CategoryImporter
class ImportFile
attr_reader :data
def initialize(base_media_url, filename)
# Load the JSON
utc = Time.now.to_i.to_s
json_file = open(base_media_url + filename + '?' + utc).read
@data = JSON.parse(json_file)
end
def apply!
data.each do |item|
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/kramdown/parser/inline_markdown.rb | Ruby | apache-2.0 | 187 | the-future | 275 | module Kramdown
module Parser
class InlineMarkdown < GFM
def initialize(source, options)
options = options.merge(hard_wrap: true)
super(source, options)
@block_parsers = %i[blank_line paragraph link_definition]
end
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/authorization/password.rb | Ruby | apache-2.0 | 187 | the-future | 832 | module Authorization
class Password
def initialize(auth, password)
@auth = auth
@password = password
end
# @return [User, nil] the user who has been authenticated
def user!
user if user&.authenticate(@password)
end
def user
if Flipper.enabled?(:aozora)
conflic... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/authorization/assertion/facebook.rb | Ruby | apache-2.0 | 187 | the-future | 3,718 | # frozen_string_literal: true
module Authorization
module Assertion
class Facebook
# The Aozora Facebook App ID
AOZORA_FACEBOOK_APP_ID = '1467094533604194'
# Facebook URL stuff
API_VERSION = 'v17.0'
URL_PREFIX = "https://graph.facebook.com/#{API_VERSION}".freeze
URL_TEMPLATE =... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/generators/rails/api_resource_route/api_resource_route_generator.rb | Ruby | apache-2.0 | 187 | the-future | 604 | if defined?(::Rails::Generators::NamedBase)
require 'rails/generators/rails/resource_route/resource_route_generator'
module Rails
module Generators
class ApiResourceRouteGenerator < ResourceRouteGenerator
def add_resource_route
return if options[:actions].present?
route_config... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/generators/rails/policy/policy_generator.rb | Ruby | apache-2.0 | 187 | the-future | 594 | if defined?(::Rails::Generators::NamedBase)
module Rails
module Generators
class PolicyGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path('templates', __dir__)
def create_policy
template_file = File.join(
'app/policies',
class_path,
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/generators/rails/jsonapi_resource/jsonapi_resource_generator.rb | Ruby | apache-2.0 | 187 | the-future | 484 | if defined?(::Rails::Generators::NamedBase)
module Rails
module Generators
class JsonapiResourceGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path('templates', __dir__)
def create_resource
template_file = File.join(
'app/resources',
cla... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | lib/generators/rails/resource_controller/resource_controller_generator.rb | Ruby | apache-2.0 | 187 | the-future | 674 | if defined?(::Rails::Generators::NamedBase)
require 'generators/jsonapi/controller_generator'
module Rails
module Generators
class ResourceControllerGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
check_class_collision suffix: 'Controller'... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/schema.rb | Ruby | apache-2.0 | 187 | the-future | 78,258 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/seeds.rb | Ruby | apache-2.0 | 187 | the-future | 433 | # Load seeds from YAML files in db/seeds/*
require 'seed_file'
MAX_ID = 2 ** 30 - 1
SEED_DIR = 'db/seeds'
previous_logger = ApplicationRecord.logger
ApplicationRecord.logger = Logger.new(nil)
Dir[Rails.root.join("#{SEED_DIR}/*.yml")].each do |f|
seed = SeedFile.new(f)
puts "==> Seeding: #{seed.model.name}"
pr... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170607055017_create_notification_settings.rb | Ruby | apache-2.0 | 187 | the-future | 556 | class CreateNotificationSettings < ActiveRecord::Migration[4.2]
def change
create_table :notification_settings do |t|
t.integer :setting_type, null: false, required: true
t.references :user, foreign_key: true, index: true, null: false
t.boolean :email_enabled, default: true, required: true
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170420035108_create_library_events.rb | Ruby | apache-2.0 | 187 | the-future | 663 | class CreateLibraryEvents < ActiveRecord::Migration[4.2]
def change
# not needed anymore, will be repalced with LibraryEvents
drop_table(:marathon_events , if_exists: true)
drop_table(:marathons , if_exists: true)
create_table :library_events do |t|
t.references :library_entry, foreign_key: tru... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20161226194618_add_encryption_to_lp_token.rb | Ruby | apache-2.0 | 187 | the-future | 206 | class AddEncryptionToLpToken < ActiveRecord::Migration[4.2]
def change
rename_column :linked_profiles, :token, :encrypted_token
add_column :linked_profiles, :encrypted_token_iv, :string
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170724025426_create_community_recommendations.rb | Ruby | apache-2.0 | 187 | the-future | 605 | class CreateCommunityRecommendations < ActiveRecord::Migration[4.2]
def change
create_table :community_recommendations do |t|
t.references :media, index: true, polymorphic: true, required: true
t.references :anime, index: true, null: true, foreign_key: true
t.references :drama, index: true, null... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20160417064936_add_mappings.rb | Ruby | apache-2.0 | 187 | the-future | 2,557 | class AddMappings < ActiveRecord::Migration[4.2]
def change
create_table :mappings do |t|
t.string :external_site, null: false
t.string :external_id, null: false
t.references :media, polymorphic: true, null: false
t.index [:external_site, :external_id, :media_type, :media_id],
uni... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170325205929_fill_nsfw_on_library_entries.rb | Ruby | apache-2.0 | 187 | the-future | 504 | require 'update_in_batches'
class FillNsfwOnLibraryEntries < ActiveRecord::Migration[4.2]
using UpdateInBatches
self.disable_ddl_transaction!
def up
LibraryEntry.joins(:anime).merge(Anime.nsfw).update_in_batches(nsfw: true)
LibraryEntry.joins(:manga).merge(Manga.nsfw).update_in_batches(nsfw: true)
en... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170602065925_add_join_tables_for_media_attribute.rb | Ruby | apache-2.0 | 187 | the-future | 1,940 | class AddJoinTablesForMediaAttribute < ActiveRecord::Migration[4.2]
def change
create_table :anime_media_attributes do |t|
t.references :anime, null: false, index: true,
foreign_key: true, required: true
t.references :media_attribute, null: false, index: true,
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170717043528_except_deleted_at_from_uniqueness_for_media_reactions.rb | Ruby | apache-2.0 | 187 | the-future | 281 | class ExceptDeletedAtFromUniquenessForMediaReactions < ActiveRecord::Migration[4.2]
def change
remove_index :media_reactions, %i[media_type media_id user_id]
add_index :media_reactions, %i[media_type media_id user_id], where: 'deleted_at IS NULL', unique: true
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170501234913_space_out_ranks_for_favorites.rb | Ruby | apache-2.0 | 187 | the-future | 794 | require 'update_in_batches'
class SpaceOutRanksForFavorites < ActiveRecord::Migration[4.2]
using UpdateInBatches
disable_ddl_transaction!
def change
execute <<-SQL.squish
CREATE TEMPORARY TABLE fav_ranks (id, rank) AS
SELECT id, ((row_number() OVER (
PARTITION BY user_id, item_type
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20200822214657_clean_up_mappings.rb | Ruby | apache-2.0 | 187 | the-future | 213 | class CleanUpMappings < ActiveRecord::Migration[5.1]
MAPPINGS = %w(anilist kitsu/genres myanimelist/genres/anime myanimelist/person)
def change
Mapping.where(external_site: MAPPINGS).delete_all
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20171025222450_clean_up_videos.rb | Ruby | apache-2.0 | 187 | the-future | 531 | class CleanUpVideos < ActiveRecord::Migration[4.2]
def change
change_column :videos, :embed_data, :jsonb, default: {}, using: 'embed_data::json::jsonb'
change_column_null :videos, :created_at, false
change_column_null :videos, :updated_at, false
change_column_null :videos, :episode_id, false
chang... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170829045027_add_aozora_columns_to_users.rb | Ruby | apache-2.0 | 187 | the-future | 701 | class AddAozoraColumnsToUsers < ActiveRecord::Migration[4.2]
def change
# Normally we'd prefer to store this in Mappings but that would slow down lookups significantly.
add_column :users, :ao_id, :string
# For most users we can just put the Aozora password in our own password_digest, but if they
# alr... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20151130083322_clean_episodes.rb | Ruby | apache-2.0 | 187 | the-future | 541 | class CleanEpisodes < ActiveRecord::Migration[4.2]
class Episode < ActiveRecord::Base
belongs_to :anime
end
def change
# Add per-episode length
add_column :episodes, :length, :integer
# Switch to Titleable concern
add_column :episodes, :titles, :hstore, default: '', null: false
add_colum... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20241108040432_create_geonames.rb | Ruby | apache-2.0 | 187 | the-future | 473 | class CreateGeonames < ActiveRecord::Migration[6.1]
def change
create_table :geonames, id: false do |t|
t.integer :geoname_id, primary_key: true
t.string :continent_code
t.string :continent_name
t.string :country_iso_code
t.string :country_name
t.string :subdivision_1_iso_code
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170125231710_create_new_casting_tables.rb | Ruby | apache-2.0 | 187 | the-future | 2,839 | class CreateNewCastingTables < ActiveRecord::Migration[4.2]
def change
# Characters (an association between Media <-> Character)
create_table :anime_characters do |t|
t.references :anime, foreign_key: true, index: true, null: false
t.references :character, foreign_key: true, index: true, null: fal... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170818204827_rename_mappings_media_to_item.rb | Ruby | apache-2.0 | 187 | the-future | 309 | class RenameMappingsMediaToItem < ActiveRecord::Migration[4.2]
def change
rename_column :mappings, :media_type, :item_type
rename_column :mappings, :media_id, :item_id
rename_index :mappings, :index_mappings_on_external_and_media,
:index_mappings_on_external_and_item
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20210919020317_remove_paperclip_columns_from_user.rb | Ruby | apache-2.0 | 187 | the-future | 649 | class RemovePaperclipColumnsFromUser < ActiveRecord::Migration[5.2]
def change
remove_column :users, :avatar_file_name
remove_column :users, :avatar_content_type
remove_column :users, :avatar_file_size
remove_column :users, :avatar_updated_at
remove_column :users, :avatar_processing
remove_col... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170616053125_add_notification_settings_for_users.rb | Ruby | apache-2.0 | 187 | the-future | 518 | class AddNotificationSettingsForUsers < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
def change
User.find_each do |user|
all_users_notifications = []
NotificationSetting::NOTIFICATION_TYPES.each do |st|
all_users_notifications << {
setting_type: st,
user: user,
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20210522191237_add_poster_image_data_to_media.rb | Ruby | apache-2.0 | 187 | the-future | 237 | class AddPosterImageDataToMedia < ActiveRecord::Migration[5.2]
def change
add_column :anime, :poster_image_data, :jsonb
add_column :manga, :poster_image_data, :jsonb
add_column :dramas, :poster_image_data, :jsonb
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170307023205_add_statuses_to_group_invites.rb | Ruby | apache-2.0 | 187 | the-future | 250 | class AddStatusesToGroupInvites < ActiveRecord::Migration[4.2]
def change
add_column :group_invites, :revoked_at, :datetime
add_column :group_invites, :accepted_at, :datetime
add_column :group_invites, :declined_at, :datetime
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170724000734_invert_default_on_hidden_column.rb | Ruby | apache-2.0 | 187 | the-future | 491 | class InvertDefaultOnHiddenColumn < ActiveRecord::Migration[4.2]
using UpdateInBatches
def change
change_column_default :follows, :hidden, false
say_with_time 'Filling hidden column for Follow' do
Follow.where(hidden: true).update_in_batches(hidden: false)
end
change_column_default :group_mem... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20190103054632_make_abbreviated_titles_required.rb | Ruby | apache-2.0 | 187 | the-future | 1,101 | class MakeAbbreviatedTitlesRequired < ActiveRecord::Migration[4.2]
using UpdateInBatches
def change
Anime.where(abbreviated_titles: nil).update_in_batches("abbreviated_titles = '{}'")
change_column_null :anime, :abbreviated_titles, false
change_column_default :anime, :abbreviated_titles, []
Manga.... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20180228020228_cull_foreign_key_constraints.rb | Ruby | apache-2.0 | 187 | the-future | 2,415 | class CullForeignKeyConstraints < ActiveRecord::Migration[4.2]
def change
# Foreign keys to User model
remove_foreign_key :ama_subscribers, :users
remove_foreign_key :amas, column: 'author_id'
remove_foreign_key :blocks, :users
remove_foreign_key :comment_likes, :users
remove_foreign_key :comm... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20181128040156_create_volumes.rb | Ruby | apache-2.0 | 187 | the-future | 523 | class CreateVolumes < ActiveRecord::Migration[4.2]
def change
create_table :volumes do |t|
t.jsonb :titles, default: {}, null: false
t.string :canonical_title
t.integer :number, null: false
t.attachment :thumbnail
t.integer :chapters_count, null: false, default: 0
t.references ... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170326222205_add_time_spent_to_library_entry.rb | Ruby | apache-2.0 | 187 | the-future | 857 | require 'update_in_batches'
class AddTimeSpentToLibraryEntry < ActiveRecord::Migration[4.2]
using UpdateInBatches
self.disable_ddl_transaction!
def up
add_column :library_entries, :time_spent, :integer
say_with_time 'Filling time_spent column' do
LibraryEntry.by_kind(:anime).update_in_batches(<<... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20161220092016_fix_onboarding_column_fills.rb | Ruby | apache-2.0 | 187 | the-future | 751 | class FixOnboardingColumnFills < ActiveRecord::Migration[4.2]
def change
# Because the ratings_count requirement has gone up, we need to start over
# on this one. The other (feed_completed) is all more lenient than before,
# so it's technically fine.
User.update_all(profile_completed: false)
User... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20181010215125_create_moderator_action_logs.rb | Ruby | apache-2.0 | 187 | the-future | 303 | class CreateModeratorActionLogs < ActiveRecord::Migration[4.2]
def change
create_table :moderator_action_logs do |t|
t.references :user, null: false
t.references :target, polymorphic: true, null: false
t.string :verb, null: false
t.timestamps null: false
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20241027091134_update_unit_status_for_titled_stuff.rb | Ruby | apache-2.0 | 187 | the-future | 767 | class UpdateUnitStatusForTitledStuff < ActiveRecord::Migration[6.1]
using UpdateInBatches
self.disable_ddl_transaction!
def change
Episode.where("titles->canonical_title !~ '^Episode \d+$'")
.update_in_batches(status: :validated)
Chapter.where("titles->canonical_title !~ '^Chapter \d+$'")
.up... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | db/migrate/20170817101151_create_user_ipaddresses.rb | Ruby | apache-2.0 | 187 | the-future | 323 | class CreateUserIpaddresses < ActiveRecord::Migration[4.2]
def change
create_table :user_ip_addresses do |t|
t.references :user, foreign_key: true, index: true, null: false
t.inet :ip_address, null: false
t.index %i[ip_address user_id], unique: true
t.timestamps null: false
end
end
e... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.