tomatoes
tomatoes copied to clipboard
Add tag parameter to tomatoes method
I wanted to get a number of tomatoes for the specified period of time and with a specified list of tags (actually, only one tag, but I think it would be nice to be possible to filter out for multiple number of tags in one request). It would be nice to have one more filter parameter as tag in tomatoes method.
I use tomatoes for tracking hours worked for each client. I want to get number of hours (number of tomatoes/2) for each client for a specific time period. I have tags for each client. What I do now is go through all tomatoes and count them. What I want to do is to run a request in SoapUI with specific parameters to get a number of tomatoes.
There's a composite index on the tomatoes
collection that includes both user_id
and created_at
. Getting a user's tomatoes that have been tagged, created in the selected period of time, should be even faster than counting them by tag, so I think we could easily add that feature in the API.
Any volunteer? cc @bugant @dalpo
See also https://github.com/tomatoes-app/tomatoes/issues/168.
@potomak would you do it with a map/reduce on mongodb?
@bugant I don't think you need a map/reduce, I think you can just run a query that count
s records with some conditions.
Ah didn't get it should only return a count, I was thinking about a filtered list (index)
I think in either case you don't need map/reduce, but you can just run a query.
query = Tomato.where(user_id: user_id).where(:created_at.gt => created_at).where(:tags.in => tags)
Note: I'm not sure if that query will work, I didn't try it.
tomatoes_count = query.count
Reference: https://docs.mongodb.com/mongoid/6.4/tutorials/mongoid-queries/
Hmm, which kind of field is tags
? Isn't it a string? If so, I'm not sure the in
will work
It should be an array.
See https://github.com/tomatoes-app/tomatoes/blob/8c9785855e0a2879b5795e6ce9127de256f2fcc9/app/models/tomato.rb#L6 and https://github.com/tomatoes-app/tomatoes/blob/8c9785855e0a2879b5795e6ce9127de256f2fcc9/lib/mongoid_tags.rb#L28