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 8623275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:14:36+00:00 2026-06-12T07:14:36+00:00

For a model like: class Thing(ndb.Model): visible = ndb.BooleanProperty() made_by = ndb.KeyProperty(kind=User) belongs_to =

  • 0

For a model like:

class Thing(ndb.Model):
    visible = ndb.BooleanProperty()
    made_by = ndb.KeyProperty(kind=User)
    belongs_to = ndb.KeyProperty(kind=AnotherThing)

Essentially performing an ‘or’ query, but comparing different properties so I can’t use a built in OR… I want to get all Thing (belonging to a particular AnotherThing) which either have visible set to True or visible is False and made_by is the current user.

Which would be less demanding on the datastore (ie financially cost less):

  1. Query to get everything, ie: Thing.query(Thing.belongs_to == some_thing.key) and iterate through the results, storing the visible ones, and the ones that aren’t visible but are made_by the current user?

  2. Query to get the visible ones, ie: Thing.query(Thing.belongs_to == some_thing.key, Thing.visible == "True") and query separately to get the non-visible ones by the current user, ie: Thing.query(Thing.belongs_to == some_thing.key, Thing.visible == "False", Thing.made_by = current_user)?

Number 1. would get many unneeded results, like non-visible Things by other users – which I think is many reads of the datastore? 2. is two whole queries though, which is also possibly unnecessarily heavy, right? I’m still trying to work out what kinds of interaction with the database cause what kinds of costs.

I’m using ndb, tasklets and memcache where necessary, in case that’s relevant.

  • 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-12T07:14:37+00:00Added an answer on June 12, 2026 at 7:14 am

    Number two is going to be financially less for two reasons. First you pay for each read of the data store and for each returned entity in a query, therefore you will be paying more for the first one which you have to Read all data and query all data. The second way you only pay for what you need.

    Secondly you also pay for backend or frontend time, and you will be using time to iterate through all your results in the first method, where as you need to spend no time for the second method.

    I can’t see a way where the first option is better. (maybe if you only have a few entities??)

    To understand how reads and queries cost you scroll down a little on:
    https://developers.google.com/appengine/docs/billing

    You will see how Read, Writes and Smalls are added up for reads, writes and queries.

    I would also just query for ones that are owned by the current user instead of visible=false and owner=current, this way you don’t need a composite index which will save some time. You can also make visible a partial index this was saving some space as well (only index it when true, assuming you never need to query for false ones). You will need to do a litte work to remove duplicates, but that is probably not to bad.

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

Sidebar

Related Questions

I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end
My model is like this class Foo(models.Model): user = models.ForeignKey(User) class Meta: abstract =
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model like: class Thing(models.Model): title = models.CharField(_('Title'), max_length=255) I want to
I've got a model like this: class Thing(models.Model): property1 = models.IntegerField() property2 = models.IntegerField()
I have an issue where I have something like this: class Thing(models.Model): def can_vote(self,
I have a model that looks like this: class Foo(ndb.Model): bar = ndb.TextProperty(required=True) #
I have a basic Django model like: class Business(models.Model): name = models.CharField(max_length=200, unique=True) email
I have a model like this: class Users(db.Model): email = db.EmailProperty(required=True, indexed=True) user_name =
So I have a model like this: class MyClass { public $customer = null;

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.