I have a database with around 7000 entries. When I load the page displaying all 7000 entries, the template takes around 7 seconds to load. How can I lower the load time? What are my options? other than caching?
See below the screenshot from network tab in Google Chrome.
You can implement lazy-loading/pagination, i.e, Initially displaying the first 'n'(say 100) entries. Then on reaching the last entry you can dynamically display the next 'n' entries using JavaScript and Ajax. Otherwise you can use Django pagination.
Related
I have a website made in django and served using gunicorn in which a single Mapbox map is loaded on the home page using mapbox-gl.js. Users can then navigate the map and change styles at will. The map is initialized and loaded only once and only in the home page. The service is billed on a "map load" basis. The Mapbox pricing page says
A map load occurs whenever a Map object is initialized, offering users unlimited interactivity with your web map.
I would have expected to see a count, if not exactly identical, at least comparable between the data recorded by Mapbox billing, the accesses to the home page recorded by Google Analytics and the hits on the home page recorded on the server access.log.
Instead, the Mapbox count is in average about 25 times higher than Analytics and the access.log, which have similar numbers.
As an example, here are the numbers for yesterday:
Analytics: home page was loaded 890 times
access.log: 1261 requests for the home page
Mapbox: 23331 map loads
I am using URL restriction from the Mapbox control panel, but I guess the enforcement is not that strict, since they strongly suggest to also rotate the token periodically (which I am already doing on a daily basis). Since I started rotating the token I noticed a slight lowering on the map loads (from an average of 28k to an average of 24k) and no noticeable changes in the access log and analytics reports.
The map implementation in Javascript is the following:
mapboxgl.accessToken = MY_TOKEN
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/myaccount/mystyle',
center: [12.381384,42.059164],
zoom: 5,
});
As I mentioned, this script is contained in the home page and is executed only once when the page is loaded. Do you have any suggestion on how to keep the maploads low? I have no problem in paying for what I'm using, but I feel there's either something wrong in the way the map loads are calculated by Mapbox, something wrong in my implementation or some sort of bot actively stealing the token.
When you change styles, that triggers a reload on the map, which will be recorded as a separate map load.
What are you trying to achieve with changing styles? Is there a small set of styles that you want to toggle between? How do they differ? There may be a way to implement that does not require fully changing the style in the map.
I have an admin site and on each page I want to display the counts for each of 5 tables.
I understand how to get the count out of the tables, but I am looking for help as to where to perform the "count" action and a best practice for storing or caching those values to be used in the blade. There are only 5 so it's not a huge load on the database.
you can perform the count in controller. But if your db tables update frequently, I think is not so right to use cache, because if you display the cached result may not be accurate.
Laravel cache
I have a page with a few tables, in total there are a few after 1000 rows.
After the tables is ready, when I click to go on another page, the route is changing in the address bar, but nothing happens until a few seconds.
Then the new page is rendered.
Why is that and what can I do?
This sounds like the new page route you are shifting to has a model hook that takes a bit to load. If that is indeed where your slowdown is then you can add a loading substate to your application to display a loading spinner of some kind.
More details available here: https://guides.emberjs.com/v2.12.0/routing/loading-and-error-substates/
E.g., I am getting more than 30,000 folder object response from the server, I need to insert into the folder tree and each object is an item controller. It's more than 10 mins to load 20,000 responses in chrome. In Firefox shows the stop script popup. Please give me the best solution for this problem.
Looking for a solution to an issue caused by large data sets forcing Ember to lock up the browser while it tries to process the data.
For pagination, I'm using tchak's handy pagination mixin to paginate approximately 13,000+ objects being loaded from a backend API.
The Ember Data objects contain an ID, one text attribute and several number attributes.
The problem is it takes close to a minute before the browser finishes processing the data, rendering the browser unusable in the meantime. Firefox even goes as far as to issue a warning that a script is using up all browser resources and suggests that script be terminated.
I've written my own pagination mixin that requests objects by range, i.e. items 10-25, and it works generally well except for one serious limitation: sorting. To sort the data, I need to make additional requests to the backend and reload the objects even if some of them have already been loaded.
I would love to be able to load all of the content upfront to simplify the process of sorting without doing additional requests to the backend API. I'm looking for guidance on how to tackle this issue but I'm open to an entirely alternative approach.
If nothing else, is it possible to reduce the resource footprint Ember places on the browser as it tries to load all 13k objects into the ArrayController?
I'm using Ember 1.0.0-pre2 with the latest Ember Data (currently at Revision 10).
On the backend is Rails 3.2.8.
Update I sidestepped the issue by loading data into an ArrayController property other than content. This brought the load times down from over a minute to only a few seconds. I then slice the requested number of items and load those into content. This works well for any number of items, at the cost of not being able to easily sort the data.
I suggest you take a look at Ember Table. The demo shows a table with 500 000 records and works very fast. Digging around the source code might help.
Can't you query a view from your db that handles the sorting? Pass in the sort conditions in the query string ?sortBy=name&sortAsc=true