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

Show department last updated dates #214

Merged
merged 4 commits into from
Oct 15, 2022
Merged

Conversation

sea-kelp
Copy link
Collaborator

@sea-kelp sea-kelp commented Oct 2, 2022

Description of Changes

Fix #82.

Adds officer, incident, and assignment last updated date for each department to the browse page.

I just threw the updated dates under the department header but let me know if you can think of a better way to display the dates!

Notes for Deployment

Make sure alembic is run!

Screenshots (if appropriate)

SPD has last updated dates for officers, incidents, and assignments while APD has none

2

Tests and linting

  • I have rebased my changes on main

  • just lint passes

  • just test passes

@sea-kelp sea-kelp requested a review from a team as a code owner October 2, 2022 19:33
@AetherUnbound
Copy link
Collaborator

What steps do you think we'll need to take in order to migrate this in production?

@AetherUnbound
Copy link
Collaborator

When I try the following steps locally, I get an error 😰 I'm not sure what is going on, but I see a migration which drops the migrate_version table?? how are any migrations happening?

  1. git checkout main
  2. just fresh-start
  3. gh pr checkout 214
  4. just db upgrade
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) table "migrate_version" does not exist

[SQL: 
DROP TABLE migrate_version]
(Background on this error at: https://sqlalche.me/e/14/f405)

@sea-kelp
Copy link
Collaborator Author

sea-kelp commented Oct 9, 2022

When I try the following steps locally, I get an error cold_sweat I'm not sure what is going on, but I see a migration which drops the migrate_version table?? how are any migrations happening?

1. `git checkout main`

2. `just fresh-start`

3. `gh pr checkout 214`

4. `just db upgrade`
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) table "migrate_version" does not exist

[SQL: 
DROP TABLE migrate_version]
(Background on this error at: https://sqlalche.me/e/14/f405)

In your local dev environment, you'll need to run just db stamp while on the main branch to set the current migration (this usually doesn't need to be done in prod since alembic records the migrations that have run but idk if we've run migrations before). Then just db upgrade should just work

@AetherUnbound
Copy link
Collaborator

Got it! I was able to run just db stamp both locally and in production, and just db upgrade ran fine locally too 😄

Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

So I've been thinking about this a bit more - I wonder if we might be able to show 3 dates: officer updated, assignments updated, and incidents updates.

Officers may be updated by volunteers (demographics and other info), so displaying that date might be useful. We may want to have that be an auto-update/TIMESTAMP NOW column.

Assignments will be updated programmatically and in bulk, but those could also be updated by volunteers. Perhaps that should be auto-updated as well?

Incidents makes sense to have separately too since that's another dimension by which we could update info!

What do you think?

@@ -59,6 +60,24 @@ def toCustomDict(self):
"unique_internal_identifier_label": self.unique_internal_identifier_label,
}

def latest_incident_date(self) -> datetime.date:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we cache these at all? Would that make sense to do/affect anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, that makes a lot of sense for these values! Do you have any suggestions on what to use for caching? I know there's the built-in functools cache but we probably want to be able to set a TTL on these dates

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added cachetools caching!

<p>

<div>
<i class="dept-{{department.id}}">Officers Updated: {{department.latest_officer_update()}}</i>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This displays as None if there's no date, could we use "No data" in those cases instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, changed!

@sea-kelp
Copy link
Collaborator Author

Got it! I was able to run just db stamp both locally and in production, and just db upgrade ran fine locally too smile

Great! (And just to re-iterate, we only need to run it once in prod to tell it to skip all the previously committed migrations)

What do you think?

So what I'm hearing is that we want to add an auto-updating date_updated column to the officers, assignments, and incidents tables and list that per-department. Is that correct?

@AetherUnbound
Copy link
Collaborator

Yes! Nailed it exactly 🚀

@@ -39,6 +42,27 @@
)


date_updated_cache = TTLCache(maxsize=1024, ttl=60)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to update the ttl but does a 12 hour ttl make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I think so!

Comment on lines +186 to +188
date_updated = db.Column(
db.DateTime, default=func.now(), onupdate=func.now(), index=True
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might make bulk updates really slow since we'd be updating lots of values in this column

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think even at scale that shouldn't be too impactful, the rows are getting updated anyway and in Postgres that means pulling out the whole row at once. I think we should be okay!

Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Looks great! Can't wait to get this out!

@sea-kelp sea-kelp merged commit 07a10fe into main Oct 15, 2022
@sea-kelp sea-kelp deleted the 82/show-dept-last-updated-dates branch October 15, 2022 20:06
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.

Show "last updated date" on department pages
2 participants