Skip to content

Instantly share code, notes, and snippets.

@stevepentler
Last active January 30, 2018 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevepentler/9e0c8c08d66860c13d4aa647c8836518 to your computer and use it in GitHub Desktop.
Save stevepentler/9e0c8c08d66860c13d4aa647c8836518 to your computer and use it in GitHub Desktop.
Availability
Availability:
Purpose:
- Assets contain their own state without any additional calls/relationships.
- single scope for assets, based on single field on Asset
- scale up features AND quicken load times
- clean up logic in views
Goals:
1. Expire Assets
2. Hold off on Publish date for Assets
3. Incorporate a more complicated approvals workflow
4. Bubble up the above 3 considerations into one "available" field on the Asset
Challenges:
1. Scope assets differently depending on permission level
- using scope that accepts permission level
- available(:adminable) { returns ALL Assets }
- available(:non_adminable) { returns ONLY available Assets }
- find all .assets calls and apply scope to all calls in API/Controllers & Views
Tech:
- Adds availability_start & availability_end fields to Assets
- Add availability field to Assets, make it an enumerable, default to 0 (approved/true)
0 = Available
1 = Expired (Date)
2 = Unpublished (Date)
3 = Pending (Approval)
- Create Scopes for available & unavailable
- AssetsService that accepts args(permission_level, resource_type, resource_id/resource_key) and returns scoped assets
- incoporate AssetsService into Controllers
- remove .assets references from views
- create indices (multiple fields) at db level for AssetsService
- Create AvailabilityService to handle logic that progresses enumerable
- Trigger AvailabilityJob that progresses assets on first minute of hour
- Index "states" for searchability in elastic search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment