# Controlling docs to sync with purge for a given user role

**URL:** <https://forum.communityhealthtoolkit.org/t/controlling-docs-to-sync-with-purge-for-a-given-user-role/1796>\
**Category:** Technical Support\
**Tags:** purge\
**Created:** [March 28, 2022, 8:24pm UTC](https://forum.communityhealthtoolkit.org/t/controlling-docs-to-sync-with-purge-for-a-given-user-role/1796 "2022-03-28T20:24:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bamatic](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/bamatic/32/1318_2.png) [@bamatic](https://forum.communityhealthtoolkit.org/u/bamatic)\
**Post date:** [March 28, 2022, 8:24pm UTC](https://forum.communityhealthtoolkit.org/t/controlling-docs-to-sync-with-purge-for-a-given-user-role/1796/1 "2022-03-28T20:24:56Z")

</div>

In our cht app we have c50\_family-\>c40\_chw\_area-\>c30\_supervisor\_area-\>c20\_health\_area-\>c10\_site  
till now we have never before add a person to the c20\_health\_area but now we have create a user at a c20\_health\_area  
When connecting with this user we have more than 30 000 docs to download to local pouchdb, and the sync never ends  
I think that this could be solved with purge,  
Is it possible to use purge to only sync some docs types for a given role ?  
by the way, we need only task and reports from 3 forms for the tb\_focal\_point role from 01-02-2022

---

<div class="post-metadata">

**Author:** ![diana](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/diana/32/2049_2.png) [@diana](https://forum.communityhealthtoolkit.org/u/diana)\
**Post date:** [March 29, 2022, 5:29am UTC](https://forum.communityhealthtoolkit.org/t/controlling-docs-to-sync-with-purge-for-a-given-user-role/1796/2 "2022-03-29T05:29:21Z")

</div>

Hi @bamatic

Purging is not a solution for this high number of documents, as it still has a performance hit server-side.  
I would recommend lowering [replication\_depth](https://docs.communityhealthtoolkit.org/apps/guides/performance/replication/) for the users at this level, and only allow them to see 1-2 levels deep. You can also control how documents beyond these levels reach your users by leveraging [supervisor signoff](https://docs.communityhealthtoolkit.org/apps/guides/performance/replication/#supervisor-signoff) .

---

<div class="post-metadata">

**Author:** ![bamatic](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/bamatic/32/1318_2.png) [@bamatic](https://forum.communityhealthtoolkit.org/u/bamatic)\
**Post date:** [March 29, 2022, 11:01am UTC](https://forum.communityhealthtoolkit.org/t/controlling-docs-to-sync-with-purge-for-a-given-user-role/1796/3 "2022-03-29T11:01:31Z")

</div>

We have c50\_family → c40\_chw\_area → c30\_supervisor\_area → c20\_health\_area hierarchy and my user is at c20\_health\_area with role tb\_focal\_point, and we have a task with this condition

```auto
appliesIf: (contact, report) => {
    return getField(report, 'tb_referral') === 'true' &&
        getField(report,'cscom_area') === user.cscom_area;
  },

```

So if I undetstand the user needs to filter at device level all reports one by one, we now that tb\_referral is only sent by three forms, and from 03-2022  
With depth:1 for tb\_focal\_point role we get 30 000 docs to sync, docs of entire health area since 2017 with more than 50 000 c50\_family and about 250 000 patient, I mean, members of c50\_family  
I thinked that with depth:1 we could reach to children reports, but not to patient reports, but even if I wold be able to limit all patient report, task won’t work

If we do our tb\_focal\_point role an online user, this replication issue would finish ?

---

<div class="post-metadata">

**Author:** ![diana](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/diana/32/2049_2.png) [@diana](https://forum.communityhealthtoolkit.org/u/diana)\
**Post date:** [March 29, 2022, 2:49pm UTC](https://forum.communityhealthtoolkit.org/t/controlling-docs-to-sync-with-purge-for-a-given-user-role/1796/4 "2022-03-29T14:49:28Z")

</div>

Hi @bamatic

Online users can’t use tasks.  
After setting depth=1, and have 30k docs, you can use purging to reduce this number.  
You can set the `tb_referral` forms to require `supervisor_signoff`([CouchDB replication | Community Health Toolkit](https://docs.communityhealthtoolkit.org/apps/guides/performance/replication/#supervisor-signoff)), so they would reach the `tb_focal_point` regardless of replication depth.
