How to get allCurrentSites by API

Iñigo Boyano, modified 7 Years ago. Junior Member Posts: 96 Join Date: 2/4/14 Recent Posts

Hi, 

I need to show all current Sites in a portlet. 

I've read that sites are Groups in liferay whit type=1 and isSite=true.

After a time searching in Internet how to do this, I found the following solution:

List<Group> listAllCompanies = GroupLocalServiceUtil.search(PortalUtil.getCompanyId(request), null, null,null, QueryUtil.ALL_POS, QueryUtil.ALL_POS);


// define a new list ONLY for sites,
List<Group> sites = new ArrayList<Group>();
// filter the original list and populate the new list
for (Group group: listAllCompanies) {
    if (group.getType() == 1 && group.isSite()) {
        sites.add(group);
    }
}


This code works properly and in sites variable I have only the sites I want to show, the problem is the performance, I have about 55000 groups to loop.

Is there any way to improve this performance or maybe using other API?

Kind regards, 

Iñigo

thumbnail
Christoph Rabel, modified 7 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts

I don't think there is an other way. Could you cache them? Maybe add a model listener that clears the cache?

thumbnail
Victor Zorin, modified 7 Years ago. Liferay Legend Posts: 1228 Join Date: 4/14/08 Recent Posts

The following code will narrow down the search query to pull the sites only (tested on 7/DXP):

            LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
            params.put("site", new Boolean(true));
            List<Group> allGroupsList = GroupLocalServiceUtil.search(companyId, params , QueryUtil.ALL_POS, QueryUtil.ALL_POS);