Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API Log #32

Merged
merged 2 commits into from
May 8, 2024
Merged

Add API Log #32

merged 2 commits into from
May 8, 2024

Conversation

driftingly
Copy link
Contributor

@driftingly driftingly commented May 7, 2024

This PR adds an API Log page to call out changes to values provided by the API.

Changes are stored in the api_log table. I'm using an additional hash column as a unique identifier for the combination of datahub_id, field, and value. This gets around the limitation of creating indexes on text columns (the value column).

With the exceptions of id, main_reference_number, image_id, and thumbnail we are tracking fields defined in ARTWORK_API_FIELDS and GALLERY_API_FIELDS:

    public const ARTWORK_API_FIELDS = [
        'id',
        'main_reference_number',
        'thumbnail',
        'artist_title',
        'artist_display',
        'medium_display',
        'date_display',
        'credit_line',
        'copyright_notice',
        'is_on_view',
        'image_id',
        'gallery_id',
    ];

    public const GALLERY_API_FIELDS = [
        'id',
        'title',
        'latitude',
        'longitude',
        'floor',
    ];

The app:api-log command is scheduled to run hourly to add entries to the log table.

Using the hash we can check if a datahub_id + field + value combination exists. This can occur if the value is changed back to a previous value. In those cases, we update the updated_at timestamp of the log record.

The getRecentChanges method uses a MySQL window function which requires MySQL 8 or later. We can get the same results with a few joins, but I found using the LAG function easier to read.

The API log page show changes where a previous value exists and is expected to be blank until changes are logged.

Screenshot 2024-05-07 at 12 18 03 PM

driftingly added 2 commits May 7, 2024 12:19
Copy link

sonarqubecloud bot commented May 7, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@driftingly driftingly marked this pull request as ready for review May 7, 2024 19:43
@zachgarwood
Copy link
Member

Sonarcloud was flagging the two uses of md5, but I marked them as safe since the hash is only used as an index key.

Copy link
Member

@zachgarwood zachgarwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! We're gonna have to use this on one of our other Twill sites.

Copy link
Member

@nikhiltri nikhiltri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! ⭐

@driftingly driftingly merged commit 57a6724 into develop May 8, 2024
2 checks passed
@driftingly driftingly deleted the drift/flag-api-updates branch May 8, 2024 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants