let me first say a big thanks for Twitterizer, it's made my dev work much easier. I'll definitely be donating. In my app, I load tweets using a webservice and since I keep a track of the last tweet, I'd like to be able to just get the count of new tweets.
is there a faster way other than using TwitterTimeline.HomeTimeline()? Since I assume this method fetches all the content?
I ended up counting new tweets clientside and hiding the content. I realised that since I was loading the content there was no need to re-fetch it again later on so I hide all of them in a div until the user expands it.
Related
using (var context = ContentSearchManager.GetIndex(index).CreateSearchContext())
{
var items = context.GetQueryable<SearchResultItem>()
.Where(item => item.TemplateId == _templateId)
.ToList();
var resultList = new List<MediaItem>();
I then go through and use conditionals to filter the results more and add them to resultList.
I add them to the list with (MediaItem)x.GetItem();
I have terrible performance, which I am sure is caused by GetItem querying the database 10,000s of times.
I need to have the results as a MediaItem due to needing to edit the fields in these items.
How can I avoid querying Sitecore for each item with GetItem() ?
Thanks,
Sitecore Noob
I tried using .GetItem() with poor performance. I also tried researching how to get back Items instead of SearchResultItem
Yes, this would be a very slow and ineffective way of loading the needed items, since you're basically loading references to all media items of the given type into memory from Solr (GetQueryable<T>) and then load everything again from the database through .GetItem(). But the pattern you're trying isn't too far off actually.
Using the SearchContext, you should do the filtering in where you get all items references you need, letting Solr do the computation. I.e. not the 10,000s of items, just the ones you're editing. Once you get the filtered result back from Solr, you perform the .GetItem() on the items you want to work with. Always check that the item (and version) actually exists after a .GetItem() since the Solr index can sometimes be out of sync with the database, so a Solr response can in rare cases reference an item that doesn't exist.
How you should write the Solr query is a bit hard to describe without knowing more details about what filters you need. In general, I'd recommend using the SolrNet API directly instead of going through the ContentSearchManager wrapper. It's sometimes hard to understand what the search manager does under the hood and you basically need to monitor the Search.log in order to verify that your code does what it's supposed to do. A small mistake in the .Where() could cause the entire media library to be loaded into memory and you'll experience the same performance issue again as you have right now. With the query you have today, it's worth noting the difference between the underlying _template and _templates index fields, as the first one (that's used in your sample code) will return items of exactly that given template while the later one will also include all items inheriting from that template.
I want to use third party's REST API providing real-time foreign exchange rates in my django app which should continuously show changing exchange rates.
my code works but only on every page reload. but I want my code to be running continuously and showing exchange rate on page even if the page is not reloaded.
def example(request)
RATE__API_URL = 'REST API url'
while True
rate = requests.get(RATE__API_URL).json()
b = rate['rates']['EURUSD']['rate']
context = {'b': b}
return render(request, 'example.html', context)
on my example.html
<h1>
{{b}}
</h1>
code is running and does not show any errors
There are a few ways you can solve your requirement and none of them are the "right way", also much of it depends of what you have in your code, so I'll try to lay them out for you, and given the extent of what needs to be done while providing some links so you can work on it, but I will not give code because you'll require a fair amount of tailored code (sorry for that) and the references are good enough for you to develop your own solution.
The first thing you have to keep in mind is than you'll need to solve two really big and really different requirements:
The first part of your solution is retrieving the data from the source in a timely manner. The second part is to have a way to update the data in the template without the need for the user to reload the page.
To retrieve the data you said you already have an API where you'll get the data, but your code is not an efficient way to approach this, and it also may generate a risk because it is prone to hit too many times the API server; the best way I can think of would be if the API has webhooks or push notifications to which you can subscribe (which I doubt), the second best choice is to implement a Celery task, that way you will be calling the data regularly, and you'll not eat the API service resources.
With the first part out of the way, what you have left to do is to implement a way to call regularly from the UI for the newest data. Perhaps the simplest way to solve it is to implement an asynchronous call with Javascript/JQuery embedded in a script inside your template, but remember:
For this to work you'll need a model to store the data (If you don't
have an use for historic data, then just keep the most recent
one).
You'll need a view that exposes the data to your UI call (one that sends a JSON)
Another solution is to implement websockets, and the best way to achieve this for Django is using django-channels. You'll have to implement two main things:
In the backed you need to define the consumers flow so you can send
the data to the UI.
In the template you need to implement the websocket connection and a way to handle the updating part of the data for the user.
If you choose this way, and given than you don't need historic data, you can obviate the model and go straight from the Celery task to the UI through the consumer.
i'm new in cakephp and I have started with version 3. I want to build a beautifull app and because I'm not good in design, I would really like to use a free template or buy one that I can use within cakephp.
So, I would really appreciate all your propositions and ideas or best practises. The easy way will be the best because I don't have a lot of time with this project. Thank you in advance.
If you don't have a lot of time like you mentioned, the easiest way to go ahead and get started is to paste a lot of the code in your default.ctp layout inside of src/Template/Layout/default.ctp.
You'll notice there are some lines of PHP already in there that are relevant to fetching blocks of css, meta tags, and other bits of code that could potentially exist throughout your project.
Find the main layout of the theme your trying to use - the one that will be consistent across most of the pages. That's the one you'll use for default.ctp. Compare what's already in default.ctp and make the comparable adjustments around the HTML in that document while keeping the important lines of PHP there as well.
For other important pages like a login or registration page, just create a new document for those, like 'login.ctp', then inside the function that loads the page (maybe 'login' inside of UsersController'), change the default layout with this line of code:
$this->viewBuilder()->layout('login'); // without the .ctp ending
This way you can create one-off layouts that don't really match any other page.
Im using NSFM's method removeItemAtURL to remove some item in iCloud, though right after that i run a NSMetaDataQuery and it can still see this item for like 3 seconds. Is there a way to fix this?
Im trying to upload an item to iCloud, and if file with such name exists i need to replace it, and then track NSMetaDataItem's uploadingPercentKey to show it to user, though as i said before, the item is still returns YES from valueForKey:NSMetadataUbiquitousItemIsUploadedKey like for 3 seconds after removal.
As far as I know there is no way to speed this up. The metadata is handled separate to your app by a daemon. That could take a little while to update the metadata, and even longer to send that metadata to the cloud, and then to other devices.
I think you just have to try to design around this delay. Assume that the metadata may not be completely up to date.
That's my first question in here, I've been looking through old questions, but nothing matched with my problem. Here it is.
I'm creating some site with one main functionality. We want this site to display content of other sites, but in a specific way. User chooses let's say two pages from five and want to see their content. He clicks button 'Display' and goes to next page where he finds let's say view from web cam, and here comes problem.
I want to cache image that is hidden behind the url from which image was downloaded, so after refresh image won't be downloaded again, but browser will get it from cache.
I've been looking through documentation of Django, but nothing seemed to be useful.
I know that I should:
1) create table which stores cache
2) add to settings.py some CACHE_BACKEND = ...
3) use #cache_page(300) before declaration of function which returns content which should be cached,
but... it doesn't seem to work.
I will be greateful if someone tells how to solve that problem, maybe with some sort of code showing the mechanism.
Cheers,
Chris.
I think that right way to do this will be to store image somewhere on your server and delete it later with cron or something similar.
Django cache framework wasn't created for the purpose you are trying to use it.