OAuthBringer / brave-rails

Rails 7 w/ basic proxy for Swapi API and minimal caching implementation.
0 stars 1 forks source link

Humanize Swapi Association Data #5

Open OAuthBringer opened 2 years ago

OAuthBringer commented 2 years ago

As noted in the README, the major issue WRT to UI support is that absence of a human friendly label for Swapi resource associations. The only values that come through are URLs.

I doubt it will be possible to handle this sanely without dropping into the database itself. The major concern there is the effort of modeling 3rd party API data. My general experience is that this is never advisable and generally doesn't scale well as you end up duplicating another dataset. This suggests to me that that a JSON column with a kind and identifier could be valuable here.

We could probably still utilize the redis cache values but handle data associations at the DB level and update the cache asynchronously. Given the inherently "stale" nature of the cached data as it stands it's probably reasonable to only display association data once it is properly formatted/associated, though this might cause confusion for the end user.

OAuthBringer commented 2 years ago

In terms of scope, this is really only relevant for any given SwapiResource, so a potential model could be

class SwapiResource respond_to :data, :kind, :swapi_id (if we went this route we'd have non unique swapi_ids so we'd need indexing on kind, swapi_id end

OAuthBringer commented 2 years ago

Ah, the other issue is that handling things dynamically it is not obvious what the human friendly displayName should be. It does however appear that the first key in the response object seems to be associated with the title/name/label. On the front-end I didn't do anything to modify the order of the columns and the first column/key value was appropriate. Thus if we preserve the ordering of the object we might be able to assume the first key is primary.