This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 10 - Pages: 1 - Last Post: 14-Feb-2019 01:42 Last Post By: jGromit Threads: [ Previous | Next ]
jGromit

Posts: 7,469
Registered: 31-Jan-2006
Change in processing sequence?
Posted: 06-Feb-2019 19:15
 
  Click to reply to this thread Reply
In a couple of my skins, rather than laboriously working around unsupported objects (like Word documents or PDF's), I simply run a little "exclude" program in predir.bsh. That means that I don't have to get fancy when it comes to things like image counters, for example. The code that I'm calling is:
private void exUnsupp(AlbumObject ao) {
	AlbumSynchronizer AlSy = new AlbumSynchronizer(engine);
	for(AlbumObject obj : ao.getChildren()) {
		cat = obj.getCategory();
		if(obj.isIncluded() && !obj.isFolder() && cat != Category.image && cat != Category.video && cat != Category.webLocation) {
			obj.setIncluded(false);
			AlSy.delete(obj);
		}
	}
	ao.setChildren(ao.getChildren());
}
This has been working fine until recently. Not sure whether it was one of the jAlbum 17 releases, or the jAlbum 18 release, but that code is now only "sort of" working. It does mark the unwanted objects as "excluded," but now it's including them in the album. Only the first time through, of course - another Make Album, and they go away as they should.

If I do the routine in init.bsh, recursively, it seems to be fine. But that's very ineffecient - if only updated subdirectories are being processed, there's no reason to traverse the whole project tree every time, even though it's quite fast.

Am I missing something?
RobM

Posts: 3,104
Registered: 4-Aug-2006
Re: Change in processing sequence?
Posted: 06-Feb-2019 20:00   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
What about using the AlbumBean get/set ignore pattern and the config setSynchronizeOutputDirectory to ensure synchronisation is set.

If that worked you wouldn’t have to process the whole of the project. Never tried it of course.
jGromit

Posts: 7,469
Registered: 31-Jan-2006
Re: Change in processing sequence?
Posted: 06-Feb-2019 20:05   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
That could work, but it might encounter exactly the same problem - by the time the ignore pattern has been set, the album objects may already have been identified. And I'm not fond of forcibly changing user settings if I don't have to.

For now, the best solution is just to do it recursively in init.bsh - it's reliable and not terribly inefficient. I was just surprised at the change.
RobM

Posts: 3,104
Registered: 4-Aug-2006
Re: Change in processing sequence?
Posted: 06-Feb-2019 20:14   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
Is there a reason why
ao.setChildren(ao.getChildren());
is outside of the for loop?

Edited by: RobM on 06-Feb-2019 19:14
What I really meant was why it isn’t inside the if statement
jGromit

Posts: 7,469
Registered: 31-Jan-2006
Re: Change in processing sequence?
Posted: 06-Feb-2019 20:30   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
You don't need to reset the "children" every time you exclude one object - doing it once per directory is sufficient.

And resetting the "children" while you're inside of a "for" loop that's going through the children strikes me as being wildly unpredictable.
RobM

Posts: 3,104
Registered: 4-Aug-2006
Re: Change in processing sequence?
Posted: 06-Feb-2019 20:38   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
jGromit wrote:
You don't need to reset the "children" every time you exclude one object - doing it once per directory is sufficient.

And resetting the "children" while you're inside of a "for" loop that's going through the children strikes me as being wildly unpredictable.

Oh for a better memory - like remembering to search the forum to find things like this
jGromit

Posts: 7,469
Registered: 31-Jan-2006
Re: Change in processing sequence?
Posted: 06-Feb-2019 22:05   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Yes, if I had to recreate one of my skins from a clean sheet, I'd be in trouble.

So, after that little excursion down Memory Impaired Lane, we're back where we started, to wit, why does this no longer work properly when called from predir.bsh?
RobM

Posts: 3,104
Registered: 4-Aug-2006
Re: Change in processing sequence?
Posted: 07-Feb-2019 00:22   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
I have tried the script with a version of Minimal and using a PDF file as a test subject.
What I'm getting is that the actual file is removed from the album output but the index page includes a thumbnail icon to the PDF. Also, the associated html file is created and left in place, which can be easily deleted by adding a poster.bsh (but you shouldn't have to do that).

So, the folder's object tree seems to be created before predir.bsh has run or completed. Is that what you are getting?
jGromit

Posts: 7,469
Registered: 31-Jan-2006
Re: Change in processing sequence?
Posted: 07-Feb-2019 00:33   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
So, the folder's object tree seems to be created before predir.bsh has run or completed. Is that what you are getting?

Yes, that's what the symptoms suggest, and that's a change from prior versions. I'm guessing it's part of something else that David has done to speed things up. Maybe something to do with creating JSON files, for example?

The "recursive in init.bsh" version works without a hitch, so I'll go with that for now. After all, I have other windmills that require tilting-at. ;)
RobM

Posts: 3,104
Registered: 4-Aug-2006
Re: Change in processing sequence?
Posted: 07-Feb-2019 10:07   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
I think this change is from version 17.1
In particular ‘ Completely rewritten skin template parser. Potentially faster as templates are now parsed once to an internal object tree (Abstract Syntax Tree) and from there evaluated to final pages multiple times. The new parser not only caches the internal object tree, it also caches compiled scriptlets for scripting languages supporting this (JavaScript and Groovy. BeanShell doesn't compile well)’
jGromit

Posts: 7,469
Registered: 31-Jan-2006
Re: Change in processing sequence?
Posted: 14-Feb-2019 01:41   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
jGromit wrote:
The "recursive in init.bsh" version works without a hitch, so I'll go with that for now.

I lied. It's all coming back to me. The problem with doing this in init.bsh is that it effectively "touches" every subdirectory. So even if you've chosen Process only updated subdirectories, it processes all of them anyway.

Back to the drawing board.... I'll probably need to keep track of whether it's actually excluded any objects before I do the ao.setChildren().

ETA: Yup, good guess. It seems that if I just set an exclusions boolean, I can avoid the nasty side-effects.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums