Craft CMS Entry::find extremely slow in custom module - craftcms

In a Craft CMS custom module I am trying to get all entries from a specific section in order to populate a dropdown using the following code:
$themes = Entry::find()
->section('colorThemes')
->limit(null)
->all();
However, somehow, this is extremely slow, resulting in a 502 Bad Gateway error in my Docker setup.
It seems that as soon as I add the ->all() part it takes forever to load.

Related

In SAP UI5 `List` the "count-indicator" [ item-N / total-M ] is missing below the "More" button

I'm developing software for 40+ years but I'm absolutely new to SAP UI5, so maybe this is very basic or a trivial problem but half a day of searching the internet brought no results:
In a Master-Detail View (defined in xml) I want to display a list of items with growing=true, growingThreshold=50 and growingScrollToLoad=false as a List.
In principle it got everything working OK now. But there is a tiny glitch, not essential, more in the category of a "nice to have":
All the examples I've seen so far show something like "[ 50 / 107 ]" below the "More" button. But in my program it is missing. I'm very sure the reason is __count is not included in the response sent from the Odata-Service implementation.
Testing directly with the SAP Gateway Service Builder (/SEGW) shows to include the count in the response $inlinecount=allpages needs to be appended to the service URI. And here it works fine - once I add this to the URI the count is included, when I leave it out or set it to none there is no count included.
Therefore the problem seems not to be in the service implementation. (At least the __count field is present or not present as expected. And I assume this is what enables the "[ # / # ]" indicator.)
When the request is then sent from the controller (implemented in JavaScript) this part is not added to the service URI, despite the OData-Model is created with defaultCountMode: "sap.ui.model.odata.CountMode.InlineRepeat". On the "Network" page of Chrome's developer tools I don't see the $inlinecount=allpages appended and also the "[ 50 / 107 ]" (or whatever is appropriate) is not shown with the "More" button.
I checked with the Chrome developer tools immediately after creating the Odata-Model if my setting in the OData-Model takes effect – and it does. And I checked once more before a request is made based on this OData-Model – and it is still there.
My only idea now is it might have something to do with the fact the request originates from the XML-view (ie. the JavaScript code created on behalf of it) and it might be using a different Odata model in which that option is not set.
How can I test for this?
Any other ideas?
Maybe an internationalization issue? (The trigger-text for displaying more entries is set to "Weiter" in German language. Maybe also the "[ # / # ]" parts needs to be re-defined elsewhere too?
The answer in the comment of Boghyon Hoffmann solved the problem:
[Use] defaultCountMode: "InlineRepeat" instead of adding a fully qualified name in string.

How do I know which IBM iLog.NET rules are getting hit during execution?

I'm using the IBM iLog.NET business rule engine (v7r1 or thereabouts) and I can't find why my rules are failing. How do I trace down what's failing, where, and why?
I've got a local object model that's calling out to my rules hosted in an IBM rules service on IIS 6.0.
About half of my rules are configured to modify one of the input objects with a new status code. The code isn't getting set when I think it should but I cannot tell conclusively which rules are getting hit.
I found that the IBM iLog.NET documentation had the answer buried deep, deep within. Persistent Google searching revealed that I can set ILOG.Rules.ExecutionServer.Trace.EventFilterCategories on my ExecutionRequest object before I send it to the server.
ExecutionRequest request = new ExecutionRequest(rulePath);
request.TraceFilter.EventFilters
= ILOG.Rules.ExecutionServer.Trace.EventFilterCategories.All;
...
ExecutionResponse response = session.Execute(request);
ILOG.Rules.ExecutionServer.Trace.Trace trace = response.Trace;
Debug.WriteLine(trace.SerializedExecutionTrace);
The serialized trace contains all the inputs and outputs for the call as well as all rules that were triggered during execution and the rules that weren't hit at all.

How to implement multilingualism in SPA

I'm currently struggling with the problem of multilingualism in an SPA.
I've come up with several solutions, like building a wrapper for the resources resx files, or saving all labels in the database, but I am wondering if any of you have found some solution which automates these steps.
Are there any practices which are specific for this problem?
For a reasonable amount of literals, I suggest to save the resources in the DB or in a .RESX file in the server. When the user logs in or you detect the language that will be used, the literals are requested by the application and saved either in a collection of your translation module or in the LocalStorage of the browser (this could be a good approach for large data).
Then this module could have some methods to retrieve the messages, probably passing a key.
Using this solution you could inject this module in the viewmodels that need to show translated literals and acces them through the view:
<p data-bind="text: resourceManager.get('M01')"></a>
For large applications that would require huge localization data to be transfered, maybe some kind of modularity could be applied and only load the resources really needed for each module/section.
I don't think making recurrent requests to the server to get the translated literals is a good practise. SPA's should provide a good user experience and loading the translated literals from the server could be a blocking issue. Text is not like an image, you can render a page without all the images loaded, imagine rendering a page without the text :o
Anyway, I think the best solution would be to keep the server as repository and create a custom JS module that takes care to get data in one or multiple loads and is able to store it somewhere in the client.
I've solved my own problem, using a custom binding and i18next.
First, I've implemented i18next for translation of my labels/buttons and other resources.
Secondly, I've added a custom Knockout bindingHandler:
ko.bindingHandlers.i18n = {
init: function (element, valueAccessor) {
var translateKey = valueAccessor();
ko.utils.setTextContent(element, $.t(translateKey));
}
};
Finally you can add the following code to your views:
<span data-bind="i18n : 'buttons.cancel'"></span>
This will automatically get the correct resource, and Knockout will handle the bindings.
Hopefully this will help others struggling with the same problem.

Customizing All errors symfony 1.4

Sorry for my English and writing through a translator.
I'm new here and I'm a bit lost in what I want, maybe you can help me out if they wish, as explained here:
I want to customize all the errors that may be produced (any status code that is a mistake. 404, 500, 204, 301 .... etc.) And also show suggestions based on the "module" and/or "action" from where the error occurred.
I also wish I could tell by the file redirection "setting.yml" application, something like this:
error_404_module: common
error_404_action: errors
error_500_module: common
error_500_action: errors
error_204_module: common
error_204_action: errors
error_301_module: common
error_301_action: errors
........
Within the "app/frontend/modules/common" in the "action.class.php" define "executeErrors" in which I receive the status code that has occurred and the module where the error occurred or except for well, getting partial show "app/frontend/modules/common/templates/_errorXXXSuccess.php" and the partial of the suggestion that I seek and extract the module "referer" where the error occurred.
Well, that's the idea, dynamic content for different types of error in different circumstances and working perfectly with the type codes 404 but not with the rest ...
I read that could place me in the middle of the event by creating a file "config/error.html.php" and "config/exception.html.php". Indeed if I produce such a 500 error and manually these files are executed. The problem is that from there I can not access variables from symfony. Because if so I could invoke "common/errors" and bad send as parameters the error status code and the module where it occurred, but it is not. From there all I can do is play with $ _SERVER and routing.yml but can not get good results because the environment is mixed with Development Production (/frontend_dev.php) and is something I also want to avoid.
That is, I want to get as in "setting.yml" does "error_404_module" and "error_404_action" but with different error codes. Thus allowing me to show my custom pages in production based on "error or exception" and/or "module or action" where the error has been released from production, and in case of being in development mode (/frontend_dev.php/....), show the symfony Dispatch.
Surely life is complicandome and has a simpler way to do what I want but after thousands of combinations do not get the right result. Even if symfony may not allow other types of error redirect from "setting.yml" is because they are reserved for him or something. I do not understand.
Please please help me because no documentation to find and secure here at least we left public for others who want to do something.
Many Thanks and greetings!
First of all - you can't get symfony to intercept all errors. Some of the errors may be server errors and the request won't even get to your application. You can reproduce some of them explicitly setting responses in symfony though, but I may not be necessary to deal with all of them.
As for the exact response: you should use a listener to hook your errors to a class that handles them according to your need. See: https://stackoverflow.com/a/7077818/580167 for implementation details.

Django admin/doc/views/ all blank or broken

I'm trying to use Django's built-in admin docs feature to make writing templates easier. Supposedly if you go to /admin/docs/views you should get documentation for every view in your application. I see a list, but none of the links work:
-) Any view listed that's related to my application just goes to a blank page with nothing but the name of the view as a header.
-) The views related to admin all give me Django 404 errors when I click on them, except those that are related to the docs itself. The docs-related links also give me blank pages. (i.e. clicking /admin/doc/filters gives a blank page with nothing but "django.contrib.admindocs.views.template_filter_index" as a title, but clicking /admin/auth/user gives me a Django 404 error
The 404 errors lead me to suspect my URLconf is wrong, but all I did was uncomment the built-in lines. The relevant sections read:
# Uncomment the admin/doc line below to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
And I have no idea what to make of the blank pages. Do I need to provide some extra meta information somewhere, like I know you need to provide the get_absolute_url on models for some of the admin features to work right?
Even if no one knows the answer, any documentation on the admin docs feature would be useful -- I've been Google all over (and searching StackOverflow) and this feature seems very little-documented.
Thanks!
You need to add 'django.contrib.admindocs' to your INSTALLED_APPS in settings.py. It should already be there and commented out. Though it would be nice if the comment in urls.py mentioned it ... Source.
I've never looked at the views admin doc pages before -- I've never had a need to. B4ut you're right, they seem to be -- lacking in potential features.
If you give your views functions docstrings (documentation), that content will appear on your "blank pages".
Most -- no, all -- of the admin sites views are actually decorated member methods of admin.sites.AdminSite. I looked around, and a view of mine which uses a decorator also suffers from the 404.
The view responsible for view details starts:
def view_detail(request, view):
if not utils.docutils_is_available:
return missing_docutils_page(request)
mod, func = urlresolvers.get_mod_func(view)
try:
view_func = getattr(import_module(mod), func)
except (ImportError, AttributeError):
raise Http404
title, body, metadata = utils.parse_docstring(view_func.__doc__)
...
You can see it tries to import the view to get info from it; if the view is actually a decorator (which probably used an internal function to wrap the real view), it won't be able to import it. eg, if you do from django.contrib.admin.sites import index in a django shell, you'll get an ImportError, whereas django.contrib.admin.site.index (note the singular site) is a:
<bound method AdminSite.index of <django.contrib.admin.sites.AdminSite object at 0x...>>
Further, that last line in my snippet seems to indicate that there's a capability for finer control over what shows up on those pages, if you care to figure out the template that util.parse_docstring uses.

Resources