import settings


def group_by_domain(domain, include_docs=True, **kwargs):
    from corehq.apps.groups.models import Group
    return Group.view(
        'groups/by_domain',
        key=domain,
        include_docs=include_docs,
        **kwargs
    )


def stale_group_by_domain(domain, include_docs=True, **kwargs):
    return group_by_domain(
        domain,
        include_docs=include_docs,
        stale=settings.COUCH_STALE_QUERY,
        **kwargs
    )


def group_by_name(domain, name, include_docs=True, **kwargs):
    from corehq.apps.groups.models import Group
    return Group.view(
        'groups/by_name',
        key=[domain, name],
        include_docs=include_docs,
        **kwargs
    )


def stale_group_by_name(domain, name, include_docs=True, **kwargs):
    return group_by_name(
        domain,
        name,
        include_docs=include_docs,
        stale=settings.COUCH_STALE_QUERY,
        **kwargs
    )


def refresh_group_views(group):
    group_by_domain(group.domain, include_docs=False, limit=1).all()
    group_by_name(group.domain, group.name, include_docs=False, limit=1).all()

@@ -1026,19 +1026,21 @@
 imit=1).
-all
+fetch
 ()%0A    g
@@ -1111,10 +1111,12 @@
 =1).
-all
+fetch
 ()%0A

refresh with fetch() instead of all()