Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:37:28+00:00 2026-06-12T01:37:28+00:00

I am using appengine with python 2.7 and webapp2 framework. I am not using

  • 0

I am using appengine with python 2.7 and webapp2 framework. I am not using ndb.model.

I have the following model:

class Story(db.Model);
    name = db.StringProperty()

class UserProfile(db.Model):
    name = db.StringProperty()
    user = db.UserProperty()

class Tracking(db.Model):
   user_profile = db.ReferenceProperty(UserProfile)
   story = db.ReferenceProperty(Story)
   upvoted = db.BooleanProperty()
   flagged = db.BoolenProperty()

A user can upvote and/or flag a story but only once. Hence I came up with the above model.
Now when a user clicks on the upvote link, on the database I try to see if the user has not already voted it, hence I do try to do the following:

  1. get the user instance with his id as up = db.get(db.Key.from_path('UserProfile', uid))

  2. then get the story instance as follows s_ins = db.get(db.Key.from_path('Story', uid))

  3. Now it is the turn to check if a Tracking based on these two exist, if yes then don’t allow voting, else allow him to vote and update the Tracking instance.

What is the most convenient way to fetch a Tracking instance given an id(db.key().id()) of user_profile and story?

What is the most convenient way to save a Tracking model having given a user profile id and an story id?

Is there a better way to implement tracking?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:37:29+00:00Added an answer on June 12, 2026 at 1:37 am

    You can try tracking using lists of keys versus having a separate entry for track/user/story:

    class Story(db.Model);
      name = db.StringProperty()
    
    class UserProfile(db.Model):
      name = db.StringProperty()
      user = db.UserProperty()
    
    class Tracking(db.Model):
      story = db.ReferenceProperty(Story)
      upvoted = db.ListProperty(db.Key)
      flagged = db.ListProperty(db.Key)
    

    So when you want to see if a user upvoted for a given story:

    Tracking.all().filter('story =', db.Key.from_path('Story', uid)).filter('upvoted =', db.Key.from_path('UserProfile', uid)).get(keys_only=True)
    

    Now the only problem here is the size of the upvoted/flagged lists can’t grow too large (I think the limit is 5000), so you’d have to make a class to manage this (that is, when adding to the upvoted/flagged lists, detect if X entries exists, and if so, start a new tracking object to hold additional values). You will also have to make this transactional and with HR you have a 1 write per second threshold. This may or may not be an issue depending on your expected use case. A way around the write threshold would be to implement upvotes/flags using pull-queues and to have a cron job that pulls and batch updates tracking objects as needed.

    This method has its pros/cons. The most obvious cons are the ones I just listed. The pros, however, may be worth it. You can get a full list of users who upvoted/flagged a story from a single list (or multiple depending on how popular the story is). You can get a full list of users with a lot fewer queries to the datastore. This method should also take less storage, index, and metadata space. Additionally, adding a user to a tracking object will be cheaper, instead of writing a new object + 2 writes for each property, you would just be charged 1 write for the object + 2 writes for the entry to the list (9 vs 3 writes for adding users to a pre-existing tracked story, or 9 vs 7 for untracked stories)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using AppEngine with the webapp framework (python). In my script I am
i am currently writing a python web-application running on google-app-engine using the webapp2 framework.
Im working on a CMS for appengine using python, I have a form page
I'm using the webapp2 framework in Google App Engine (Python). In webapp2 exception handling:
So I have a python webapp on Google App Engine and am using the
I'm running Django on AppEngine (python 2.7 runtime) using their Cloud SQL. I've setup
I am writing a python program for google appengine using jinja2 as my template
I've got a GAE in Python and I am using the Channel API: https://developers.google.com/appengine/docs/python/channel/functions
I am using the Google Appengine remote shell, with Python. I am walking through
I'm writing a simple app with AppEngine, using Python. After a successful insert by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.