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

Track number of visits on workspace invitation page #571

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

nikochiko
Copy link
Member

  • add visits tracking for workspace invitation page
  • show visits on workspace invite admin

Q/A checklist

  • If you add new dependencies, did you update the lock file?
poetry lock --no-update
  • Run tests
ulimit -n unlimited && ./scripts/run-tests.sh
  • Do a self code review of the changes - Read the diff at least twice.
  • Carefully think about the stuff that might break because of this change - this sounds obvious but it's easy to forget to do "Go to references" on each function you're changing and see if it's used in a way you didn't expect.
  • The relevant pages still run when you press submit
  • The API for those pages still work (API tab)
  • The public API interface doesn't change if you didn't want it to (check API tab > docs page)
  • Do your UI changes (if applicable) look acceptable on mobile?
  • Ensure you have not regressed the import time unless you have a good reason to do so.
    You can visualize this using tuna:
python3 -X importtime -c 'import server' 2> out.log && tuna out.log

To measure import time for a specific library:

$ time python -c 'import pandas'

________________________________________________________
Executed in    1.15 secs    fish           external
   usr time    2.22 secs   86.00 micros    2.22 secs
   sys time    0.72 secs  613.00 micros    0.72 secs

To reduce import times, import libraries that take a long time inside the functions that use them instead of at the top of the file:

def my_function():
    import pandas as pd
    ...

Legal Boilerplate

Look, I get it. The entity doing business as “Gooey.AI” and/or “Dara.network” was incorporated in the State of Delaware in 2020 as Dara Network Inc. and is gonna need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Dara Network Inc can use, modify, copy, and redistribute my contributions, under its choice of terms.

@nikochiko
Copy link
Member Author

we do this for shortened URLs

ShortenedURL.objects.filter(id=surl.id).update(clicks=F("clicks") + 1)

more detailed tracking is added there with VisitorClickInfo - which tracks IP, location, etc. looks like we don't need that

@nikochiko nikochiko requested a review from devxpy December 18, 2024 16:22
@nikochiko nikochiko assigned nikochiko and devxpy and unassigned nikochiko Dec 18, 2024
@devxpy
Copy link
Member

devxpy commented Dec 18, 2024

we do this for shortened URLs

ShortenedURL.objects.filter(id=surl.id).update(clicks=F("clicks") + 1)

more detailed tracking is added there with VisitorClickInfo - which tracks IP, location, etc. looks like we don't need that

Should we call it clicks here as well for consistency?

Tracking the visitor click info would be interesting too for building dashboards, but can leave out for first

@nikochiko
Copy link
Member Author

@devxpy FYI, pushed the renaming

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added visit tracking functionality to workspace invitations by introducing a 'clicks' field to track page views and displaying this information in the admin interface.

  • Added clicks field to WorkspaceInvite model with default=0 in migration 0007_workspaceinvite_clicks.py
  • Inconsistent naming between 'clicks' field in model/migration and 'visits' references in views.py needs alignment
  • Added clicks counter to WorkspaceInviteAdmin list_display and readonly_fields for visibility
  • Optimized save() call in accept() method by specifying update_fields parameter
  • Uses Django's F() expression in views.py for race-condition-safe counter increments

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

4 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +32 to +38
readonly_fields = [
"clicks",
"auto_accepted",
"has_expired",
"created_at",
"updated_at",
]
Copy link

Choose a reason for hiding this comment

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

logic: clicks field added to readonly_fields but not included in WorkspaceInviteInline.readonly_fields - could lead to inconsistent behavior

Copy link
Member

Choose a reason for hiding this comment

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

@nikochiko thoughts?

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR continues the implementation of workspace invitation tracking functionality. Here's a focused summary of the recent changes:

  • Updated invitation_page function in workspaces/views.py to increment the clicks counter using F() expressions for atomic updates
  • Maintained consistent field naming by using 'clicks' instead of 'visits' throughout the codebase
  • Implemented race-condition-safe counter increments using Django's F() expression
  • Added proper field tracking in admin interface for monitoring invitation clicks

The changes are straightforward and maintain good database practices by using atomic updates. No major concerns with the implementation.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@devxpy
Copy link
Member

devxpy commented Dec 25, 2024

please squash and merge too, for nicer git history

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.

2 participants