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

Fix user last active updating #1105

Merged
merged 2 commits into from
Mar 9, 2021

Conversation

danitrod
Copy link
Collaborator

PR Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

PR Checklist

  • - Latest master branch merged
  • - PR title descriptive (can be used in release notes)
  • - Passes Tests

Description

A login now updates the user's last active status to the current time, as discussed in #984. The update is done in the userSignedIn method in the store. I tested with a custom pin and the last active info is updating correctly now.
Also, in order to not backup a user every time he logs in, I added a shallow comparator on a previous and updated user, to check if lastActive is the only field updated. This hasn't been tested though as I'm not sure how to test the backup function and see the backup data. If the test is desirable I'd be happy to test it, just will need some directions.

Git Issues

Closes #984

Screenshots/Videos

@cypress
Copy link

cypress bot commented Feb 23, 2021



Test summary

62 0 0 0


Run details

Project onearmy-community-platform
Status Passed
Commit f365a77 ℹ️
Started Mar 9, 2021 8:27 PM
Ended Mar 9, 2021 8:33 PM
Duration 05:51 💡
OS Linux Ubuntu Linux - 16.04
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@chrismclarke
Copy link
Member

Thanks for adding this, I've been a bit busy recently but will do my best to review and respond properly about the backup functions this week.

@chrismclarke chrismclarke self-requested a review March 1, 2021 05:42
@@ -1,4 +1,21 @@
import { DBDoc, IDBDocChange } from '../models'
import { IDBDocChange } from '../models'
import { IUserDB } from 'src/models/user.models'
Copy link
Member

Choose a reason for hiding this comment

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

Due to a limitation with how the functions folder is organised, imports from the local 'src' folder won't actually be recognised on build (the way typescript resolves paths is fiddly at best, there's quite a bit of tooling out there which is better for working in these monorepo structures such as lerna or yarn workspaces (particularly with newer yarn 2.x), but haven't got round to updating.

So for now can you just change it to a relative import (../models)

prevUser: IUserDB,
updatedUser: IUserDB,
): boolean => {
return Object.keys(prevUser).some(
Copy link
Member

Choose a reason for hiding this comment

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

really like the implementation, efficient to just look for first key barring exclusions where data has changed. I also tested locally and working as intended.

Copy link
Member

@chrismclarke chrismclarke 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, just one small import to fix which I've added a comment for.

@chrismclarke
Copy link
Member

Also, if you're updating this PR could you also include the code to run the user backup function? (I'm not sure why it was ever removed, I'm guessing by mistake during some code refactoring).

It can be called from functions/src/userUpdates/index.ts within the handleUserUpdates trigger, i.e.

export const handleUserUpdates = functions.firestore
  .document(`${DB_ENDPOINTS.users}/{id}`)
  .onUpdate(async (change, context) => {
    await processCountryUpdates(change)
    await backupUser(change)            <-------------------------- Call here to run on user updates
  })

I quickly revisited the current implementation for testing these backend functions. It still could do with a lot of improvement although I'm reluctant to spend too much time on this as I'm expecting/hoping that over the next year we will be able to replace firebase entirely in the project. I've sent an invite so you can receive edit access to the testing firebase site, and there is some general notes in functions\README.md

More specifically it involves installing and logging in to the firebase cli, running the start script from the functions folder, and then making manual updates to the emulated database to see changes (e.g. I created a user document and tried updating different fields to check if the revision would be made)

image

@chrismclarke chrismclarke added Review allow-preview ✅ Has received manual check for malicious code and can be safely built for preview Review: Changes Requested 🗨️ Code reviewed, pending update to changes requested labels Mar 9, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2021

Visit the preview URL for this PR (updated for commit af7369e):

https://onearmy-next--pr1105-984-fix-last-active-9y5wrlft.web.app

(expires Thu, 08 Apr 2021 20:09:33 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@danitrod danitrod requested a review from chrismclarke March 9, 2021 20:45
Copy link
Member

@chrismclarke chrismclarke left a comment

Choose a reason for hiding this comment

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

Great, thanks for checking and addressing all the feedback points. Merging

@chrismclarke chrismclarke merged commit f53a94b into ONEARMY:master Mar 9, 2021
@danitrod danitrod deleted the 984-fix-last-active branch March 9, 2021 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Review allow-preview ✅ Has received manual check for malicious code and can be safely built for preview Review: Changes Requested 🗨️ Code reviewed, pending update to changes requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] - User last active does not automatically update
2 participants