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

datastore: Export query struct fields #4341

Open
RPGillespie6 opened this issue Jun 29, 2021 · 0 comments
Open

datastore: Export query struct fields #4341

RPGillespie6 opened this issue Jun 29, 2021 · 0 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@RPGillespie6
Copy link

RPGillespie6 commented Jun 29, 2021

Is your feature request related to a problem? Please describe.
I'm trying to use Redis to cache datastore entities and queries. The problem is that the Query struct does not export any of its fields (kind, ancestor, etc) so I have no way of generating a cache key from a provided query, other than using hacky reflection techniques or building a wrapper around it.

Describe the solution you'd like
Export fields that could be used to generate a redis key:

type Query struct {
	Kind       string
	Ancestor   *Key
	Filter     []filter
	Order      []order
	Projection []string

	distinct   bool
	distinctOn []string
	keysOnly   bool
	eventual   bool
	Limit      int32
	offset     int32
	start      []byte
	end        []byte

	namespace string

	trans *Transaction

	err error
}

Describe alternatives you've considered
Current best alternative is to build a wrapper around Query so a way to uniquely id query can be captured or to use hacky reflection (which I don't want to do since a later version of datastore may break it).

As an example:
Given a key datastore.Key I can generate a redis key with fmt.Sprintf("%s:%d", key.Kind, key.ID). With a query though... I have no way of uniquely fingerprinting it so it's hard to map a query to cached results of that query. If you don't want to expose those fields, maybe a Fingerprint() method would be fine as well.

i.e. if you had a q datastore.Query you could call q.Fingerprint() which returns a string that uniquely identifies it (could be as simple as kind:ancestor:filters:order:projection:limit, for example User:::Last Name::100)

@RPGillespie6 RPGillespie6 added the triage me I really want to be triaged. label Jun 29, 2021
@product-auto-label product-auto-label bot added the api: datastore Issues related to the Datastore API. label Jun 29, 2021
@dmahugh dmahugh added priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Jun 29, 2021
@yoshi-automation yoshi-automation removed the triage me I really want to be triaged. label Jun 29, 2021
@crwilcox crwilcox assigned dmahugh and unassigned crwilcox Sep 21, 2021
@telpirion telpirion assigned telpirion and unassigned dmahugh Sep 23, 2022
@telpirion telpirion assigned triplequark and unassigned telpirion Nov 4, 2022
@bhshkh bhshkh assigned bhshkh and unassigned triplequark Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

7 participants