Is there a way to speed up this sorting function?

Currently, I am sifting through approximately 12,000 users, which amounts to over 1,000 each day. I am using MongoDB with monk and have implemented the following sorting code.

class User {
constructor(doc) {
    this.username = doc.username
    this.kills = doc.kills;
    this.deaths = doc.deaths;
}};

let res = await Calls.getAllUsers()

let users = res.map((doc) => new User(doc));

const sorted = users.sort((a, b) => b.kills - a.kills);

const whereIam = sorted.indexOf(users.find((u) => u.username === user_grab)) + 1;

The variable "whereIam" is causing performance issues, resulting in approximately 20 seconds delay for every query.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing a substantial update in MVC with the help of Slickgrid

Working on optimizing an MVC application that uses SlickGrid for grid edits. The grid can vary from 500 to 25,000 rows with around 40 columns. While the grid functions well, I'm facing challenges when it comes to posting changed data to my controller ...

Updating the ContextKey of the DynamicPopulateExtender based on the selected value from a DropDownList dynamically

I am facing an issue with my DynamicPopulateExtender control. I need it to render HTML based on the value of an asp:DropDownList. The problem lies in writing the JavaScript code that can fetch the dropdown value, assign it to the DynamicPopulate control&ap ...

Despite successfully connecting to my webservice, the ajax function encounters an error

<script type='text/javascript'> $(document).ready(function () { $("#submit").click(function (e) { e.preventDefault(); var userName = $("#username").val(); var pwd = $("#password").val(); authenticate(use ...

Determine the overall sum following the modification of rows

Need assistance with calculating the Grand Total of all rows to display at the bottom of a table using JQuery 1.9. Below is the JavaScript code: <script language="javascript"> $(".add_to_total").on('change', function() { var total = 0; $( ...

Vue/Vuex - using async dispatch for AJAX requests in multiple components

I am working with vuex and using a store module to load user lists in my app through ajax. After the list is loaded, it doesn't fetch again if it's already present in the vuex store. I have implemented this logic in the main application layout as ...

Having trouble getting a NodeJS sample app to start up because it can't locate the 'config' file?

I am currently delving into the world of Node.js and have been attempting to launch a sample application that I recently acquired from a git repository: https://github.com/madhums/node-express-mongoose-demo Despite diligently following all the provided i ...

Enhanced User Experience Through Triggered Content Recommendations based on Scrolling Patterns

When a user scrolls beyond a certain point on a webpage, I would like a recommended content popup to slide out from the right side at the bottom of the page. An excellent example can be seen on USAToday where a blue recommended box appears as you scroll d ...

What is the best way to remove a nested JSON key in a dynamic manner

Here is a sample json for reference: { "search": { "facets": { "author": [ ], "language": [ { "value": "nep", "count": 3 }, { "value": "urd", "count": 1 } ], "source": [ { "value": "West Bengal ...

Learn the process of submitting tag values using JohMun/vue-tags-input feature

I am a beginner in Vue.js and I am looking to implement an input field with multiple tags (user skills) using a Vue.js component. Although I have managed to make it work, I am struggling to figure out how to submit the tags in a form. Below is my code: T ...

How to apply a series of spaces using span/tspan with jquery/javascript

Check out this fiddle: http://jsfiddle.net/jzLu4toe/3/ <span id='tghj'></span> $('#tghj').text('Hey There'); I'm facing an issue where I need to insert multiple spaces inside a span element. ...

Update database upon drag-and-drop using jQuery

I have a dataset (shown below) that undergoes sorting by 'section'. Each item is placed into a UL based on its section when the page loads. My goal is to automatically update the section in the database when a user drags an item to a different s ...

Tips for disabling autofocus on Mui Menu Items

Incorporating a search functionality within a custom Mui Select component where the user can input a city or country to filter down the options list. The current issue is that when a user types a letter that matches the first letter of an option, the opt ...

When starting up for the first time, mongod does not create any preallocated journal files in the designated folder

Context: I recently installed two RPM packages on CentOS 6.3(Final) 64-bit with an Ext4 file system. The packages are: mongo-10gen-2.2.1-mongodb_1.x86_64.rpm mongo-10gen-server-2.2.1-mongodb_1.x86_64.rpm Issue: Upon the initial startup of mongod, no pre ...

What is the process for implementing a security rule for sub-maps with unique identifiers in Firebase?

I am looking to implement a security rule ensuring that the quantity of a product cannot go below zero. Client-side request: FirebaseFirestore.instance .collection('$collectionPath') .doc('$uid') .update({'car ...

Tips for managing player rounds updates

How can I make the number of rounds increase by 1 every time a card is clicked, rather than jumping to 4 and staying there? The initial value is set at 'let rounds = 0;' in my code. <!DOCTYPE html> <html lang="en"> < ...

Can someone help clear up this confusion with CSS?

Why is image 6.png selected, when all the images are direct descendants of the div shape? Thank you for your assistance, it's greatly appreciated. As far as I know, it should select all the divs because they are all direct descendants of the div #shap ...

Utilizing attributes as scope properties within AngularJS

I am currently working on a directive and I need to pass the Attributes (Attrs) to the $scope, however, I am facing some difficulties in achieving this. Specifically, my goal is to assign attributes in my template based on the name set in my date-picker ta ...

Styling the scrollbar for the PDF element on an HTML page

I have a div that contains an object "linked" to a .pdf file. Is it possible to customize the scrollbar style using CSS or JavaScript/jQuery? <div id="container"> <object data="document.pdf" type="application/pdf" ...

Automated user roster refresh

I have an online user list that is dynamically generated using a SQL query on a database table. How can I implement real-time updates to the webpage when a new user logs in? What specific code do I need to include for this functionality? Appreciate any g ...

There seems to be a problem with the output when trying to display the message "You said ${reply}"

In the following code snippet, vanilla.js is being used with ATOM as the text editor and running on nodejs via terminal: 'use strict'; const Readline = require('readline'); const rl = Readline.createInterface({ input:process.stdin, ...