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

Optimization needed for /api/srch/profiles API query #3147

Closed
jywarren opened this issue Jul 25, 2018 · 24 comments
Closed

Optimization needed for /api/srch/profiles API query #3147

jywarren opened this issue Jul 25, 2018 · 24 comments
Labels
break-me-up break up for cleaner code separation, discrete tests, and, easier and iterative collaboration help wanted requires help by anyone willing to contribute high-priority
Milestone

Comments

@jywarren
Copy link
Member

jywarren commented Jul 25, 2018

Probably due to very high number of users in the system (300k+?) this query needs some optimization as I believe it's responsible for some outages, and is running very slow!

https://publiclab.org/api/srch/profiles?srchString=aya

@icarito - and be aware of this @milaaraujo @stefannibrasil 👍

@jywarren jywarren added this to the API milestone Jul 25, 2018
@jywarren
Copy link
Member Author

jywarren commented Jul 25, 2018

I believe this is a double-ended string match that's running against the whole table - inefficient...

User.order('id DESC')
.where(status: 1)
.where('username LIKE ?', '%' + input + '%')
.limit(limit)

This is especially apparent when trying to autocomplete usernames after typing @... in a comment...

def self.search(query)
User.where('MATCH(username, bio) AGAINST(?)', query)
end

Can we use this new full-text search function instead of the above code?

@jywarren
Copy link
Member Author

#3148 - one attempt at this... any suggestions?

@jywarren
Copy link
Member Author

Optimizing front end w @ryzokuken too:

https://github.com/ichord/At.js

var at_config = {
at: "@",
callbacks: {
remoteFilter: function(query, callback) {
$.getJSON("/api/srch/profiles?srchString=" + query, {}, function(data) {
if (data.hasOwnProperty('items') && data.items.length > 0) {
callback(data.items.map(function(i) { return i.docTitle }));
}
});
}
},
limit: 20
},

@jywarren
Copy link
Member Author

@jywarren
Copy link
Member Author

i also limited to 10 results in the reply, in
d4f1624

@jywarren
Copy link
Member Author

Opened a caching issue at #3149!

@jywarren
Copy link
Member Author

@ryzokuken is working on a debouncing strategy https://css-tricks.com/debouncing-throttling-explained-examples/

@jywarren
Copy link
Member Author

We could further optimize the User query above by selecting only username, status, id... but the full text search also searches bio so we'd need to make an alternate form of User.search that does not search bios... i'll open another PR for that.

@jywarren
Copy link
Member Author

#3150 - searching only usernames!

@jywarren
Copy link
Member Author

ok awesome, previously this had ~600 results, now only 10: https://publiclab.org/api/srch/profiles?srchString=aya

@stefannibrasil
Copy link

yeah, we were planning to set aside some weeks to work only on improving the search service, but we can start this week, beginning with the #3069.

@stefannibrasil
Copy link

We believe we addressing those concerns here #3134 could you please take a look there? we left some comments along the code reflecting the questions we had while working on the endpoint. Thanks!

@jywarren
Copy link
Member Author

jywarren commented Aug 1, 2018

Also implementing @ryzokuken's optimization here: https://www.irccloud.com/pastebin/yTikGnHV/

@jywarren
Copy link
Member Author

jywarren commented Aug 1, 2018

Ok, and working on this in #3172 but unable to get the debounce to work yet...

@Radhikadua123
Copy link
Contributor

Radhikadua123 commented Oct 30, 2018

@jywarren As I can see, #3134 was merged. Is this issue still valid ? If yes, then I can have a deep look inside it.

@jywarren
Copy link
Member Author

#3172 and #3149 are still unresolved, and we'd love help with them!! Thank you!

@Radhikadua123
Copy link
Contributor

I see. I would love to give it a try later on.

@jywarren
Copy link
Member Author

jywarren commented Oct 30, 2018 via email

@jywarren
Copy link
Member Author

@milaaraujo is this potentially of interest for the API work you're doing?

@milaaraujo
Copy link
Collaborator

milaaraujo commented Dec 11, 2018

Not directly... I think! What exactly needs to be done here? We are already using the full-text search function. @jywarren

@jywarren jywarren added help wanted requires help by anyone willing to contribute break-me-up break up for cleaner code separation, discrete tests, and, easier and iterative collaboration labels Jan 10, 2019
@jywarren
Copy link
Member Author

I'm thinking this on caching results: #3149 potentially

@jywarren
Copy link
Member Author

Thanks!

@milaaraujo
Copy link
Collaborator

Can we close this one, @jywarren?

@jywarren
Copy link
Member Author

jywarren commented Feb 5, 2019

Yes, esp since it's being worked on in #4670. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
break-me-up break up for cleaner code separation, discrete tests, and, easier and iterative collaboration help wanted requires help by anyone willing to contribute high-priority
Projects
None yet
Development

No branches or pull requests

4 participants