basic user search impl
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -107,7 +107,7 @@ gem "neighbor"
|
||||
gem "disco"
|
||||
gem "faiss"
|
||||
|
||||
group :production do
|
||||
group :production, :staging do
|
||||
gem "rails_semantic_logger"
|
||||
end
|
||||
# gem "pg_party"
|
||||
@@ -116,3 +116,4 @@ gem "tailwindcss-rails", "~> 2.0"
|
||||
|
||||
gem "react-rails"
|
||||
gem "shakapacker"
|
||||
gem "rack-cors"
|
||||
|
||||
@@ -216,6 +216,8 @@ GEM
|
||||
raabro (1.4.0)
|
||||
racc (1.6.2)
|
||||
rack (2.2.6.2)
|
||||
rack-cors (2.0.1)
|
||||
rack (>= 2.0.0)
|
||||
rack-mini-profiler (3.0.0)
|
||||
rack (>= 1.2.0)
|
||||
rack-proxy (0.7.6)
|
||||
@@ -373,6 +375,7 @@ DEPENDENCIES
|
||||
pry
|
||||
pry-stack_explorer
|
||||
puma (~> 5.0)
|
||||
rack-cors
|
||||
rack-mini-profiler
|
||||
rails (~> 7.0.4, >= 7.0.4.2)
|
||||
rails_semantic_logger
|
||||
|
||||
@@ -2,6 +2,21 @@ class Domain::Fa::ApiController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token,
|
||||
only: %i[ enqueue_objects object_statuses ]
|
||||
|
||||
def search_users
|
||||
name = params[:name]
|
||||
limit = (params[:limit] || 10).to_i.clamp(0, 15)
|
||||
users = relevant = Domain::Fa::User.where([
|
||||
"(name ilike :name) OR (url_name ilike :name)",
|
||||
{ name: "#{ReduxApplicationRecord.sanitize_sql_like(name)}%" },
|
||||
]).order(name: :asc).
|
||||
limit(limit).
|
||||
pluck(:id, :name, :url_name).
|
||||
map do |id, name, url_name|
|
||||
{ id: id, name: name, url_name: url_name }
|
||||
end
|
||||
render json: { users: users }
|
||||
end
|
||||
|
||||
def object_statuses
|
||||
fa_ids = (params[:fa_ids] || []).map(&:to_i)
|
||||
url_names = (params[:url_names] || [])
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useState } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { debounce, isEmpty } from "lodash";
|
||||
|
||||
const HOST = "http://scraper.local:3001";
|
||||
const COMMON_LIST_ELEM_CLASSES = `
|
||||
w-full p-2 pl-8
|
||||
text-xl font-light
|
||||
@@ -36,7 +37,7 @@ function UserSearchBar(props) {
|
||||
}
|
||||
setShowSpinner(true);
|
||||
const response = await fetch(
|
||||
`/api/fa/search_users?name=${encodeURIComponent(userName)}`
|
||||
`${HOST}/api/fa/search_users?name=${encodeURIComponent(userName)}`
|
||||
);
|
||||
const { users } = await response.json();
|
||||
setShowSpinner(false);
|
||||
|
||||
@@ -82,6 +82,12 @@ production:
|
||||
legacy:
|
||||
<<: *legacy_prod
|
||||
|
||||
staging:
|
||||
redux:
|
||||
<<: *redux_prod
|
||||
legacy:
|
||||
<<: *legacy_prod
|
||||
|
||||
worker:
|
||||
redux:
|
||||
<<: *redux_prod
|
||||
|
||||
118
config/environments/staging.rb
Normal file
118
config/environments/staging.rb
Normal file
@@ -0,0 +1,118 @@
|
||||
require "active_support/core_ext/integer/time"
|
||||
|
||||
Rails.application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
config.hosts << "localhost"
|
||||
config.hosts << "scraper.local"
|
||||
|
||||
# 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, allowing both threaded web servers
|
||||
# and those relying on copy on write to perform better.
|
||||
# Rake tasks automatically ignore this option for performance.
|
||||
config.eager_load = true
|
||||
|
||||
# Full error reports are disabled and caching is turned on.
|
||||
config.consider_all_requests_local = false
|
||||
config.action_controller.perform_caching = true
|
||||
|
||||
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
|
||||
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
|
||||
# config.require_master_key = true
|
||||
|
||||
# Disable serving static files from the `/public` folder by default since
|
||||
# Apache or NGINX already handles this.
|
||||
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
|
||||
|
||||
# Compress js / css assets
|
||||
# config.assets.css_compressor = :sass
|
||||
# config.assets.js_compressor = :uglifier
|
||||
config.assets.gzip = true
|
||||
|
||||
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
||||
config.assets.compile = false
|
||||
|
||||
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
||||
# config.asset_host = "http://assets.example.com"
|
||||
|
||||
# Specifies the header that your server uses for sending files.
|
||||
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
|
||||
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
|
||||
|
||||
# Store uploaded files on the local file system (see config/storage.yml for options).
|
||||
config.active_storage.service = :local
|
||||
|
||||
# Mount Action Cable outside main process or domain.
|
||||
# config.action_cable.mount_path = nil
|
||||
# config.action_cable.url = "wss://example.com/cable"
|
||||
# config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
|
||||
|
||||
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
||||
# config.force_ssl = true
|
||||
|
||||
# Include generic and useful information about system operation, but avoid logging too much
|
||||
# information to avoid inadvertent exposure of personally identifiable information (PII).
|
||||
config.log_level = :info
|
||||
|
||||
# Prepend all log lines with the following tags.
|
||||
config.log_tags = [:request_id]
|
||||
|
||||
# Use a different cache store in production.
|
||||
# config.cache_store = :mem_cache_store
|
||||
|
||||
# Use a real queuing backend for Active Job (and separate queues per environment).
|
||||
# config.active_job.queue_adapter = :resque
|
||||
# config.active_job.queue_name_prefix = "legacy_explorer_production"
|
||||
|
||||
config.action_mailer.perform_caching = false
|
||||
|
||||
# Ignore bad email addresses and do not raise email delivery errors.
|
||||
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
||||
# config.action_mailer.raise_delivery_errors = false
|
||||
|
||||
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
||||
# the I18n.default_locale when a translation cannot be found).
|
||||
config.i18n.fallbacks = true
|
||||
|
||||
# Don't log any deprecations.
|
||||
config.active_support.report_deprecations = false
|
||||
|
||||
# Use default logging formatter so that PID and timestamp are not suppressed.
|
||||
config.log_formatter = ::Logger::Formatter.new
|
||||
|
||||
# Use a different logger for distributed setups.
|
||||
# require "syslog/logger"
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
|
||||
|
||||
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
||||
logger = ActiveSupport::Logger.new($stdout)
|
||||
logger.formatter = config.log_formatter
|
||||
config.logger = logger
|
||||
|
||||
# $stdout.sync = true
|
||||
# config.rails_semantic_logger.add_file_appender = false
|
||||
# config.semantic_logger.add_appender(io: $stdout, formatter: config.rails_semantic_logger.format)
|
||||
end
|
||||
|
||||
config.colorize_logging = true
|
||||
config.log_tags = {
|
||||
ip: ->request {
|
||||
request.headers["HTTP_CF_CONNECTING_IP"] || request.remote_ip
|
||||
},
|
||||
api_token: ->request { request.params[:api_token] || "(nil api token)" },
|
||||
user_name: ->request {
|
||||
api_token = request.params[:api_token]
|
||||
if api_token
|
||||
user = ApplicationController::API_TOKENS[api_token]
|
||||
user || "(nil user)"
|
||||
else
|
||||
"(nil api_token)"
|
||||
end
|
||||
},
|
||||
}
|
||||
|
||||
# Do not dump schema after migrations.
|
||||
config.active_record.dump_schema_after_migration = false
|
||||
end
|
||||
8
config/initializers/cors.rb
Normal file
8
config/initializers/cors.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
Rails.application.config.middleware.insert_before 0, Rack::Cors, debug: true do
|
||||
if Rails.env.staging?
|
||||
allow do
|
||||
origins "localhost:3000"
|
||||
resource "/api/fa/search_users", headers: :any, methods: [:get, :options]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -18,6 +18,9 @@ default: &default
|
||||
production:
|
||||
<<: *default
|
||||
|
||||
staging:
|
||||
<<: *default
|
||||
|
||||
development:
|
||||
direct: {}
|
||||
proxy-1: {}
|
||||
|
||||
Reference in New Issue
Block a user