tomatoes icon indicating copy to clipboard operation
tomatoes copied to clipboard

Add tag parameter to tomatoes method

Open andrew-chiz-muzychuk opened this issue 7 years ago • 8 comments

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.

andrew-chiz-muzychuk avatar Jun 17 '17 17:06 andrew-chiz-muzychuk

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.

andrew-chiz-muzychuk avatar Jun 17 '17 17:06 andrew-chiz-muzychuk

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 avatar Jun 18 '17 04:06 potomak

@potomak would you do it with a map/reduce on mongodb?

bugant avatar Oct 25 '18 07:10 bugant

@bugant I don't think you need a map/reduce, I think you can just run a query that counts records with some conditions.

potomak avatar Oct 25 '18 13:10 potomak

Ah didn't get it should only return a count, I was thinking about a filtered list (index)

bugant avatar Oct 25 '18 13:10 bugant

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/

potomak avatar Oct 25 '18 13:10 potomak

Hmm, which kind of field is tags? Isn't it a string? If so, I'm not sure the in will work

bugant avatar Oct 25 '18 13:10 bugant

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

potomak avatar Oct 25 '18 14:10 potomak