An API to help Granblue Fantasy players create and share teams and strategies.
Find a file
Justin Edmund 6cf11e6517
Jedmund/fix image embeds 4 (#177)
* Update gitignore

There is a mystery postgres folder and we are going to ignore it

* Add migrations

* Update preview state default to pending
* Adds indexes
* Adds PgHero and PgStatements

* Update .gitignore

* Update Gemfile

Production:
- `newrelic_rpm`

Development:
- `pg_query`
- `prosopite`

* Configure Sidekiq

Create job for cleaning up party previews

* Configure Prosopite and remove CacheFreeLogger

* Enable query logging

* Update api_controller.rb

Add N+1 detectioin via Prosopite in development/test environments

* Refactor canonical object blueprints

* Refactor grid object blueprints

* Remove N+1 from grid object models

Reimplementing `character` `summon` and `weapon` was making N+1s which made queries really slow

* Add counter caches to party

* Add preview generation helpers

The Party model can respond to queries about its preview state with the following models:
- `schedule_preview_generation`
- `preview_content_changed?`
- `preview_expired?`
- `should_generate_preview?`
- `ready_for_preview?`
- `needs_preview_generation?`
- `preview_relevant_attributes`

Removes the following methods:
- `schedule_preview_regeneration`
- `preview_relevant_changes?`

* Add cache to is_favorited(user)

* Refactored PartyBlueprint to minimize N+1s

* Remove preview expiry constants

These are defined in the Coordinator instead

* Add method comments

* Create parties_controller.rbs

* Update logic and logs

* Updates excluded methods and calculate_count

* Use `includes` instead of `joins`
* Use a less-insane way of counting

* Adds a helper method for party privacy

* Update filter condition helpers

Just minor refactoring

* Fix old view name in PartyBlueprint

* Refactor parties#create

* Remove redundant return

* Update parties_controller.rbs

* Update parties#index

* Update parties_controller.rb

Updates apply_includes and apply_excludes, along with modifying id_to_table and build_query

* Update parties_controller.rb

Adds the rest of the changes, too tired to write them all out. Some preview generation, some filtering

* Refactor parties#index and parties#favorites

These are mostly the same methods, so we remove common code into build_parties_query and render_paginated_parties

* Alias table name to object to maintain API consistency

* Maintain API consistency with raid blueprint

* Optimize party loading by adding eager loading to `set_from_slug`

- Refactored `set_from_slug` to use `includes` for eager loading associated models:
  - `user`, `job`, `raid` (with `group`)
  - `characters` (with `character` and `awakening`)
  - `weapons` (with `weapon`, `awakenings`, `weapon_key1`, `weapon_key2`, `weapon_key3`)
  - `summons` (with `summon`)
  - `guidebooks` (`guidebook1`, `guidebook2`, `guidebook3`)
  - `source_party`, `remixes`, `skills`, and `accessory`
- This change improves query efficiency by reducing N+1 queries and ensures all relevant associations are preloaded.
- Removed redundant favorite check as it was not necessary in this context.

* Refactor grid blueprints

- **GridCharacterBlueprint:**
  - Removed `:minimal` view restriction on `party` association.
  - Improved nil checks for `ring1`, `ring2`, and `earring` to prevent errors.
  - Converted string values in `awakening_level`, `over_mastery`, and `aetherial_mastery` fields to integers for consistency.
  - Ensured `over_mastery` and `aetherial_mastery` only include valid entries, filtering out blank or zero-modifier values.

- **GridWeaponBlueprint:**
  - Removed `:minimal` view restriction on `party` association.
  - Ensured `weapon` association exists before accessing `ax`, `series`, or `awakening`.
  - Improved conditional checks for `weapon_keys` to prevent errors when `weapon` or `series` is nil.
  - Converted `awakening_level` field to integer for consistency.

- **GridCharacterBlueprint:**
  - Removed `:minimal` view restriction on `party` association.

* Update raid blueprints

- Show flat representation of raid group in RaidBlueprint's nested view
- Show nested representation of raid in RaidGroupBlueprint's full view

* Move n+1 detection to around_action hook

* Improve handling mastery bonuses

- Improved handling of nested attributes:
  - Replaced old mastery structure with new `rings` and `awakening` assignments.
  - Added `new_rings` and `new_awakening` virtual attributes for easier updates.
  - Updated `assign_attributes` to exclude `rings` and `awakening` to prevent conflicts.

- Enhanced parameter transformation:
  - Introduced `transform_character_params` to process `rings`, `awakening`, and `earring` more reliably.
  - Ensured proper type conversion (`to_i`) for numeric values in `uncap_level`, `transcendence_step`, and `awakening_level`.
  - Improved error handling for missing values by setting defaults where needed.

- Optimized database queries:
  - Added `.includes(:awakening)` to `set` to prevent N+1 query issues.

- Updated strong parameters:
  - Changed `rings` from individual keys (`ring1`, `ring2`, etc.) to a structured array format.
  - Refactored permitted attributes to align with the new nested structure.

* Eager-load jobs when querying job skills

* Eager load raids/groups when querying

* Update users_controller.rb

More efficient way of denoting favorited parties.

* Update awakening.rb

- Removes explicitly defined associations and adds ActiveRecord associations instead

* Update party.rb

- Removes favorited accessor
- Renames derivative_parties to remixes and adds in-built sort

* Update weapon_awakening.rb

- Removes redefined explicit associations

* Update grid_character.rb

- Adds code transforming incoming ring and awakening values into something the db understands

* Update character.rb

Add explicit Awakenings enum

* Update coordinator.rb

Adds 'queued' as a state for generation
2025-02-09 22:50:18 -08:00
.github Update PULL_REQUEST_TEMPLATE.md (#166) 2025-01-16 00:34:58 -08:00
app Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
bin June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
config Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
db Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
lib Fix image embeds 3 (#176) 2025-01-20 03:55:22 -08:00
log Restart on Rails 2020-09-14 18:30:54 -07:00
public Fix image embeds 3 (#176) 2025-01-20 03:55:22 -08:00
sig Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
spec Update seeds and fix deletion bug (#110) 2023-06-23 20:34:08 -07:00
storage Restart on Rails 2020-09-14 18:30:54 -07:00
test Restart on Rails 2020-09-14 18:30:54 -07:00
tmp Restart on Rails 2020-09-14 18:30:54 -07:00
vendor Restart on Rails 2020-09-14 18:30:54 -07:00
.env Hotfix so weapon key search translates ints to arrays (#140) 2023-12-30 06:20:22 -08:00
.gitignore Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
.ruby-gemset Updates to Ruby 3.3.7 (#163) 2025-01-15 21:31:49 -08:00
.ruby-version Updates to Ruby 3.3.7 (#163) 2025-01-15 21:31:49 -08:00
.solargraph.yml Create .solargraph.yml 2020-09-25 10:41:23 -07:00
config.ru Restart on Rails 2020-09-14 18:30:54 -07:00
ENDPOINTS.md Create ENDPOINTS.md (#169) 2025-01-18 03:22:55 -08:00
Gemfile Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
Gemfile.lock Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
LICENSE Create LICENSE (#172) 2025-01-18 03:25:32 -08:00
railway.toml Fix image embeds 3 (#176) 2025-01-20 03:55:22 -08:00
Rakefile Restart on Rails 2020-09-14 18:30:54 -07:00
README.md Update README.md (#171) 2025-01-18 03:25:40 -08:00

Hensei API

Project Overview

Hensei is a Ruby on Rails API for managing Granblue Fantasy party configurations, providing comprehensive tools for team building, character management, and game data tracking.

Prerequisites

  • Ruby 3.3.7
  • Rails 8.0.1
  • PostgreSQL
  • AWS S3 Account (for image storage)

System Dependencies

  • Ruby version manager (rbenv or RVM recommended)
  • Bundler
  • PostgreSQL
  • Redis (for background jobs)
  • ImageMagick (for image processing)

Initial Setup

1. Clone the Repository

git clone https://github.com/your-organization/hensei-api.git
cd hensei-api

2. Install Ruby

Ensure you have Ruby 3.3.7 installed. If using rbenv:

rbenv install 3.3.7
rbenv local 3.3.7

3. Install Dependencies

gem install bundler
bundle install

4. Database Configuration

  1. Ensure PostgreSQL is running
  2. Create the database configuration:
rails db:create
rails db:migrate

5. AWS S3 Configuration

Hensei requires an AWS S3 bucket for storing images. Configure your credentials:

EDITOR=vim rails credentials:edit

Add the following structure to your credentials:

aws:
  s3:
    bucket: your-bucket-name
    access_key_id: your-access-key
    secret_access_key: your-secret-key
    region: your-aws-region

6. Run Initial Data Import (Optional)

rails data:import

7. Start the Server

rails server

Environment Variables

While most configurations use Rails credentials, you may need to set:

  • DATABASE_URL
  • RAILS_MASTER_KEY
  • REDIS_URL

Performance Considerations

  • Use Redis for caching
  • Background jobs managed by Sidekiq
  • Ensure PostgreSQL is optimized for full-text search

Security

  • Always use rails credentials:edit for sensitive information
  • Keep your master.key secure and out of version control
  • Regularly update dependencies

Deployment

Recommended platforms:

  • Railway.app (We use this)i98-i
  • Heroku
  • DigitalOcean App Platform

Deployment steps:

  1. Precompile assets: rails assets:precompile
  2. Run migrations: rails db:migrate
  3. Start the server with a production-ready web server like Puma

Troubleshooting

  • Ensure all credentials are correctly set
  • Check PostgreSQL and Redis connections
  • Verify AWS S3 bucket permissions

License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0-only) with additional non-commercial restrictions.

Key points:

  • You are free to use and modify the software for non-commercial purposes
  • Any modifications must be shared under the same license
  • You must provide attribution to the original authors
  • No warranty is provided

See the LICENSE file for full details.

Contact

For support, please open an issue on the GitHub repository.