Mongodb – Optimise mongo aggregation query
Is there any better way to write this query? { $facet: { results: [ { $match: { $expr: { $and: [{ $gte: ["$var1", 1] }, { $gte: ["$var2", 200] }], }, }, }, { $sort: { var1: 1 } },…
Is there any better way to write this query? { $facet: { results: [ { $match: { $expr: { $and: [{ $gte: ["$var1", 1] }, { $gte: ["$var2", 200] }], }, }, }, { $sort: { var1: 1 } },…
I am developing a chatting application. I have written a SQL to get the active chats associated with the user. It used to get user to user chat and group chats based on sort it in descending order based on…
I need to fill an array with the properties from each continent for each year. Is there a better and more optimal way of iterating through the following object without using nested for-loops which have a time complexity of O(n2)…
I have an array of strings, which are either an asterisk by itself ("*") or something else. I want to "merge" consecutive asterisks as follows: If there are one or more asterisks in a row, remove them from the array,…
I built a dynamic query that returns Total count of entries in CTE Paginated entries from CTE List of column names used in CTE Requested page size and page number The beauty of in returning total count + pagination in…
there is a small table with 10 rows. and sometimes a simple request can take more than 1 second. Query_time: 1.874935 Lock_time: 1.370841 UPDATE table SET value = value + 1 WHERE key = operation_key LIMIT 1; the request is…
I've got double foreach loop. Script takes urls from one file and tries to find it in html code of pages from another file. Of course that reading so many pages is pretty hard for server so I want to…
I'm trying to optimise the Digital Ocean droplet that my Laravel web app is running on, and have noticed that MySQL is constantly using ~50% of its 1GB RAM. By far the most common and well-attested method for decreasing MySQL's…
a potentially huge json-lines file with objects of known structure is to be converted to csv with headers. example {"name":"name_0","value_a":"value_a_0","value_b":"val_b_0"} {"name":"name_1","value_a":"value_a_1","value_b":"val_b_1"} {"name":"name_2","value_a":"value_a_2","value_b":"val_b_2"} {"name":"name_3","value_a":"value_a_3","value_b":"val_b_3"} {"name":"name_4","value_a":"value_a_4","value_b":"val_b_4"} expected output "name","value_a","value_b" "name_0","value_a_0","val_b_0" "name_1","value_a_1","val_b_1" "name_2","value_a_2","val_b_2" "name_3","value_a_3","val_b_3" "name_4","value_a_4","val_b_4" currently tried (if (input_line_number == 1 ) then…
I need to calculate a 2D matrix multiplied with 2D vector. Both use 32 bit floats. I'm hoping to do this using SSE (any version really) for speed optimization purposes, as I'm going to be using it for realtime audio…