ProcessWire Weekly #106

The 106th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, core updates, sites, and more. Read on!

This week we have a neat new API method to introduce in our core updates section, a couple of modules to share, and of course a brand new site of the week to showcase.

Although 106 isn't a particularly special number, at least not for yours truly, it's worth pointing out that as of this issue ProcessWire Weekly is officially two years old. Huge thanks to everyone supporting this project, and here's to many more years to come!

We hope you'll enjoy our weekly update, and please don't hesitate to drop us a line if there's anything you'd like to ask, suggest, or disagree with. We're always happy to receive feedback, and your opinion really matters to us. Have a great weekend.

Latest core updates: ProcessWire 3.0.19 adds new API method $pages->findMany()

As Ryan explains in the latest blog post at the blog, the latest version of the 3.x (devns) branch of ProcessWire, 3.0.19, introduces a brand new API method: $pages->findMany(). Based on the concept suggested by our friends at Avoine, this feature vastly improves the scalability of some of ProcessWire's core features.

Find without a predefined limit: potential memory issues ahead

While regular $pages->find() is both easy to use and very powerful, when you need to find and iterate over a very large quantity of pages – thousands of pages – you're going need a limit or you'll risk running out of memory. Loading a huge amount of pages into memory simply doesn't scale very well.

The usual workaround for this is performing the find in multiple batches and clearing the page cache after each batch. While definitely feasible, this approach is not always exactly pretty, and at the very least it will require adding some otherwise unnecessary boilerplate code to the mix.

Avoiding memory issues by making use of $pages->findMany()

This is where $pages->findMany() comes into play: while it behaves otherwise like $pages->find(), it avoids loading found pages into memory unless you specifically request a specific page. The documentation for ProcessWire 3.x describes this quite fittingly as a kind of a "lazy loading" feature for pages.

Using this approach you can find tens or hundreds of thousands of pages at once, and even if you then decide to iterate over those pages one by one, ProcessWire will make sure that you don't easily exceed a reasonable amount of run-time memory. While the system still loads pages in groups, this happens automatically behind the scenes.

$pages->find() vs. $pages->findMany(), which should I use?

Technically speaking find() still has the upper hand in terms of performance for most regular, small-scale needs, while findMany() is much better when dealing with a large number of pages. Unless you need to handle a lot of pages you don't need to change anything, but it's definitely good to be aware of the alternative.

In case you're worried that having two similar find methods will add complexity to the API, it's worth pointing out that Ryan has already suggested merging this feature with the existing find method at some point. This way ProcessWire could decide on a case-by-case basis which method is preferable. The best of both worlds, so to speak.

Don't forget to check out Ryan's latest blog post for more details – including use cases and initial test results – about the newly added findMany() method. For questions and general discussion there's also a dedicated support forum board for the post.

New module: TextformatterCurrency

According to the official description at the modules directory Textformatter Currency is "a locale-aware currency formatter for ProcessWire". When enabled for a field used to store monetary values, this module is able to convert field values for output purposes into the representation that best matches current locale.

Locale-aware currency formatting shouldn't be confused with converting values from one currency to another – this task would be better suited for the Currency Conversion module. In a nutshell locale-aware currency formatting means keeping the currency intact, but rendering the entire value according to the rules set by the locale.

This is best explained using an example found from the module description:

Input GBP 50.99 | EUR 100 gives £50.99 + €100.00 when viewed in browser set to British English but gives 50,99 £GB + 100,00 € using a browser set to French.

The module is able to sniff the locale from the headers sent by the browser of current user, but you can also specify the locale via module settings. PHPs Internationalization extension is used behind the scenes to achieve a valid conversion.

Big thanks to netcarver for sharing this module with us. For more information, check out the modules directory page for Textformatter Currency, and for questions and support requests be sure to visit the dedicated support forum board for the module. Thanks!

New module: Admin Deselect Radio Buttons

Another module by netcarver, Admin Deselect Radio Buttons was actually released back in April. This small module adds a small but sometimes crucial feature to ProcessWire's Admin interface: the ability to deselect radio buttons.

Once checked, native radio buttons can't be easily cleared without reloading the page. While this could definitely be considered a feature, in some cases it can also prove out to be problematic: if you want to allow only one value to be selected radio buttons are definitely better than checkboxes, but this means that undoing a selection is difficult.

Admin Deselect Radio Buttons tackles this issue by adding a checkbox-style unchecking support for the Admin GUI. This feature is probably familiar to many of us from various questionnaires and such, and is just about as unobtrusive solution as one can imagine.

You can find the download link to the module from the dedicated support forum thread. Thanks to netcarver for sharing this module with us. While pretty small and simple, it's definitely a very cool addition too!

Site of the week: Aimhigher Northhamptonshire

Our latest site of the week belongs to a not-for-profit organization known as Aimhigher Northhamptonshire Ltd.

Aimhigher Northhamptonshire Ltd provides services related to learning, training, self improvement, and finding employment both for young people and adults. They work together with schools, colleges, work-based learning providers and community projects in order to better realize their goals.

The Aimhigher Northhamptonshire site is based on the UIkit front-end framework and can hardly be described as particularly flashy, but it is a very well designed, good looking site nevertheless. There are a ton of little details that make the site easy and fun to browse, not to mention that they have clearly given some special consideration to accessibility – definitely a goal we can get behind too.

The Aimhigher Northhamptonshire website was built by Keywave Media Solutions Ltd. Big thanks to Keywave for sharing this site with us – your work is definitely top-notch!

Stay tuned for our next issue

That's it for the 106th issue of ProcessWire Weekly. We'll be back with more news, updates, and content Saturday, 28th of May. As always, ProcessWire newsletter subscribers will get our updates a few days later.

Thanks for staying with us, once again. Hope you've had a great and productive week, and don't forget to check out the ProcessWire forums for more interesting topics. Until next week, happy hacking with ProcessWire!

This post has 2 comments:

Ryan on Tuesday 24th of May 2016 13:43 pm

Teppo, congrats on 2 years! Thanks for all that you've done here and for ProcessWire! Looking forward to the years ahead.

Teppo on Wednesday 25th of May 2016 0:12 am

Thanks, Ryan – appreciate that. It's been a real treat for me to see both ProcessWire and the community behind it grow and mature during the past few years :)

Post a comment