Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

python - Creating your own activity logging in GAE/P

I'd like to log user activity in my app for presentation to users and also for administrative purposes. My customers are companies so there are three levels at which I may be presenting activity:

  1. Activity of a single user
  2. Activity of all users of a company
  3. All activity

To do the logging, I would create a model to store the log entries. I see a few ways of doing this.

First, I could store each logged activity in its own entity and then query as needed:

class Activity(ndb.Model):
    activity = ndb.StringProperty()
    user_id = ndb.StringProperty()
    company_id = ndb.StringProperty()

Second, I could store all activity of a user in a single entity:

class UserActivity(ndb.Model):
    activity = ndb.StringProperty(repeated=True) # Note this is now a list
    company_id = ndb.StringProperty()

Third, I could store all activity of a company in a single entity:

class CompanyActivity(ndb.Model):
    activity = ndb.StringProperty(repeated=True) # Would store user_id here somehow

What are the functionality/performance tradeoffs in the three options? I understand that there are potential contention issues with the second and third options if there are frequent put transactions, but let's assume that is not an issue for the sake of discussion.

For the second and third options, are there any significant advantages in reducing the total number of datastore entities (since they would be consolidated into fewer entities)? Or should I just go with the first option?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...