Appcelerator Alloy data binding - transfrom is called twice? - appcelerator

I have a collection with model transform function. I transform my model to the desired structure and return it.
To debug something I have printed out to console the item id.
This collection is binded to a ListView and in my controller I call the collection fetch method.
What I suddenly notice since I'm outputting the item id to the console is that I see it running twice. This is my output:
[INFO] item.id = 51120f4b-a60b-4c46-a776-453e60faede3
[INFO] item.id = 874ba847-95eb-bb65-b1a5-4e8d8950bcf2
[INFO] item.id = 77590380-6045-6105-0604-e905807060ba
[INFO] item.id = 51120f4b-a60b-4c46-a776-453e60faede3
[INFO] item.id = 874ba847-95eb-bb65-b1a5-4e8d8950bcf2
[INFO] item.id = 77590380-6045-6105-0604-e905807060ba
You can see that each item is processed twice and they are processed in the same order. So I'm guessing I have some performance hit here due to the fact that it's running twice. Any explanation?
Looking more into it - the read operation from the db occurs only once. It's the transform method that is called twice.

Related

How to set nested objects?

i am trying to set the redux state but not the whole object tree but just a sub-tree.
Object graph -
Parent
|----Header
|----Summary
|-----List of objects
I am using following code -
return state.setIn([Parent, 'Summary'], summary)
It sets the summary object but the list of objects is null. What am I doing wrong ?
you can try it in this way:
let newSummary = Object.assign(Parent.summary, {...yourchange});
this.setState(Object.assign(Parent.summary, {
summary: newSummary
})})

Prevent implicit closure of a ScrollableResults on exit from a Grails service

I have a Grails application thread (a Quartz job) that does batch processing of a large number of records. The processing creates a new object with a different object type that is based on the input object. The new object refers to the input object. The input object is immutable and is not modified in any way.
I'm attempting to use a ScrollableResults obtained from the Grails criteria API to iterate the set of input objects efficiently. The outer iteration is done outside of a transaction because I want to calculate progress on the batch by counting the number of processed records that I have created. Each output record is created in a separate transaction.
After I successfully process the first input object retrieved from the ScrollableResults, I get the following exception when trying to fetch the second input object:
Message: could not advance using next()
Line | Method
->> 107 | execute in com.spiekerpoint.reacs.ForecastJob
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 102 | execute in grails.plugins.quartz.GrailsJobFactory$GrailsJob
| 202 | run . . in org.quartz.core.JobRunShell
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
Caused by SQLException: Operation not allowed after ResultSet closed
->> 1086 | createSQLException in com.mysql.jdbc.SQLError
The input object, and by extension the outer cursor (ScrollableResult), have joined the implicit transaction created by the Grails service call that does the processing for the new record and the cursor is implicitly closed.
Here are simplified versions of the classes and job code that are in play:
class InventoryItem {
String name
}
class ForecastInventoryItem {
InventoryItem item
Long forecast
}
/**** Quartz Job Code ****/
//Create a cursor based query for satellite inventory items
Closure criteriaClosure = forecastService.queryInventoryItemsWithCursor(forecast)
ScrollableResults cursor = InventoryItem.createCriteria().scroll(criteriaClosure)
//Forecast the inventory items
while (cursor.next()) {
//Get the next inventory item to forecast from the cursor
InventoryItem inventoryItem = cursor.get()[0]
if (!inventoryItem) {
log.error("Failed to fetch inventory item from scrollable result.")
return
}
//Forecast the item
log.info("Forecasting inventory item ${inventoryItem}")
forecastService.forecastInventoryItem(forecast, inventoryItem)
}
cursor.close()
I have tried the following things to "detach" the inventoryItem instance from the forecastService initiated transaction:
I wrapped the call to forecastService.forecastInventoryItem in a withNewTransaction {} block.
I passed in the inventoryItem id to the service within the new transaction and let it acquire a new copy of the InventoryItem record.
It still insists on closing the cursor on the close of the service transaction.
I could of course put everything into a single transaction but then I loose the benefit of being able to poll for progress on the processing because they won't show up to any thread (ie. the controllers) until the entire transaction closes.
Any thoughts from the Grails gurus on how I might be able to separate the outer cursor from the transaction and keep it from implicitly closing on return from the service call?
I was able to work around the transaction boundary problem inside the Quartz job by avoiding loading and handling of any objects in the job execution handler. I did this by eliminating the cursor and changing the criteria search to use a projection that returns a list of ids for the matching InventoryItem records. I then added a set of ForecastService methods that accepted an id for the InventoryItem and then fetched the InventoryItem record in the method. I also added a service method to flush the Hibernate session cache periodically (every 30 transaction was optimal for this particular case) keeping my memory usage low and avoiding the thrashing that kills performance when doing batch processing in a Hibernate session.
The result was a performance increase from ~3 items per second to ~80 items per second. Also, because each forecast runs in its own transaction, I can asynchronously track the progress of the forecast process by counting the number of ForecastInventoryItem object relative to the number of target InventoryItems.
In summary, do not deal with any domain objects in the job execution method because they will communicate the transaction boundary into the job.

Getting prevalue id from umbraco dropdown list

I'm currently trying to implement AJAX results filtering on a certain page.
I created the dropdowns(on the client side), so that they have the umbraco prevalue id as their value.
I will then send this id to the server, rather than the text value. Then I loop through my content to find items with this same id.
The problem, however, is that I can't figure out how to get the value id from the property. Everything either returns the text value, or just a 0 value.
This is being performed in an ApiController.
These are all of the options I've tried:
IPublishedContent root = Umbraco.TypedContentAtRoot().First();
var downloads = root.Children.Where(q => q.Name == "Downloads").SingleOrDefault();
foreach (var item in downloads.Children)
{
var test = item.GetPropertyValue<int>("classification");
var testing = item.GetProperty("classification");
var testVal = testing.DataValue;
var testValToo = testing.GetValue<int>();
var testThree = testing.Value;
}
These are the results in order:
- 0
- IPublishedProperty
- "textValue"
- 0
- "textValue"
Is it possible to get the selected value id from a dropdownlist property? Or is string matching my only option to compare values?
EDIT:
Nevermind, found the solution. Posting the answer here, in case someone else needs it.
I was using the data type dropdownlist. I should have been using dropdownlist:publishing keys.
dropdownlist only ever returns a value. dropdownlist:publishing keys, however, returns the prevalue id, rather than the text value.
Source
Something like this perhaps.
library.GetPreValueAsString(node.GetProperty<int>("sectionType")).ToLower()

Why are my s.prop variable instances not getting updated properly in SiteCatalyst?

I have this weird problem in Sitecatalyst where I am unable to account for about 50% of my traffic recored via props. I update the s.pageName and a s.prop1 with same values before making the s.t() call. I get equal total values in the Pages report and the Page Views , but when I check the prop1 variable report, i have close to 50% of the traffic missing. I am at a loss to figure out why the traffic is missing, any help from Omniture developers would be appreciated.
I am using a dictionary to iterate over the props/variable and their values that need to be set.
var paramsMap = {
"pageName": "pageName",
"pageType": "prop1" },
params = {
"pageName":"mysite - demopage",
"pageType":"demopage"};
for (var key in params)
s[paramsMap[key]] = params[key];

Parallel Process is not updating WPF Collection List

In my WPF application, I have a Data Grid which populates with a ObservableCollection collection. Suppose I have such 10 student data in the grid. Each student is capable of doing 2 long running works or process and updates the status of the process back to the grid. I want to do those 2 process simultaneously. So I used Task and Parallel.Invoke methods. The work flow is as follows.
I populated the Student data collection in the Grid.
I clicked on a start button.
In the click event of the start button, i did the following code.
foreach (Student stud in StudentLists)
{
stud.Status = "started..";
Task.Factory.StartNew(() => StartProcess(stud));
}
In the StartProcess,
Parallel.Invoke(() =>
{
MarkService ms = new MarkService(stud_data);
Student s = ms.GetMarkProcess(); // This will return the stud_data in the above line
Student studitem = StudentLists.Where(x => x.RollID == s.RollID).FirstOrDefault(); // find the student in the grid
if (studitem != null)
{
studitem.Status = "Mark Got it"; // if find, updating the status
}
},
() =>
{
SentMarks(poll); // this is another method to be executed parallel
}
);
When executing all the 10 students process, each student in the grid became the same data.
Or only 2 or 1 student in the Grid is showing Status "Mark Got it". Other rows show "started.." status only.
Why this is not updating the collection.
I have used INotofyPropertyChanged and raisng the event when property updated.
In the XAML, each binding is used in Two way mode.
There is no error. But the 1 or 2 items in the student collection is updating some times. Sometimes the collection contains the last students data for all the 9 items.
It is not updating the exact student object in the Grid. what is wrong in my code ?
Any help in this case ???
The problem here is that your referencing a UI control from another thread. You should create an in memory data structure that a grid can use as DataSource (anything that implements IEnumerable). I would suggest using the ConcurrentBag data structure for parallelized code (http://msdn.microsoft.com/en-us/library/dd997305.aspx). Once you've updated each of the student records in the ConcurrentBag you set the grid's datasource to that bag.

Resources