@@ -1432,7 +1432,7 @@ func internalRetrieveWallet(
14321432
14331433 ownerId := w .OwnedBy
14341434 owner := accGlobals .OwnersById [ownerId ].WalletOwner ()
1435- apiWallet := lInternalWalletToApi (now , b , w , owner , includeChildren )
1435+ apiWallet := lInternalWalletToApi (now , b , w , owner , includeChildren , util . OptNone [ int ]() )
14361436
14371437 b .Mu .RUnlock ()
14381438 accGlobals .Mu .RUnlock ()
@@ -1447,6 +1447,7 @@ func lInternalWalletToApi(
14471447 w * internalWallet ,
14481448 owner accapi.WalletOwner ,
14491449 includeChildren bool ,
1450+ filterChildrenByIdleTimeInDays util.Option [int ],
14501451) accapi.WalletV2 {
14511452 groups := w .AllocationsByParent
14521453 apiWallet := accapi.WalletV2 {
@@ -1559,7 +1560,19 @@ func lInternalWalletToApi(
15591560 }
15601561
15611562 if includeChildren {
1563+ activeChildren := map [AccWalletId ]util.Empty {}
1564+ if filterChildrenByIdleTimeInDays .Present && filterChildrenByIdleTimeInDays .Value > 0 {
1565+ from := now .AddDate (0 , 0 , - filterChildrenByIdleTimeInDays .Value )
1566+ activeChildren = lUsageActiveChildrenInWindow (from , now , w .Id )
1567+ }
1568+
15621569 for childId , _ := range w .ChildrenUsage {
1570+ if len (activeChildren ) > 0 {
1571+ if _ , isActive := activeChildren [childId ]; isActive {
1572+ continue
1573+ }
1574+ }
1575+
15631576 childWallet := b .WalletsById [childId ]
15641577 childOwner := accGlobals .OwnersById [childWallet .OwnedBy ]
15651578 g := childWallet .AllocationsByParent [w .Id ]
@@ -1598,7 +1611,7 @@ func internalRetrieveWalletByAllocationId(
15981611 if iWallet != nil {
15991612 owner := accGlobals .OwnersById [iWallet .OwnedBy ]
16001613 if owner != nil {
1601- wallet = lInternalWalletToApi (now , bucket , iWallet , owner .WalletOwner (), false )
1614+ wallet = lInternalWalletToApi (now , bucket , iWallet , owner .WalletOwner (), false , util . OptNone [ int ]() )
16021615 wId = walletId
16031616 found = true
16041617 bucket .Mu .RUnlock ()
@@ -1620,6 +1633,23 @@ type walletFilter struct {
16201633
16211634 IncludeChildren bool
16221635 RequireActive bool
1636+
1637+ FilterChildrenByIdleTimeInDays util.Option [int ]
1638+ }
1639+
1640+ func lUsageActiveChildrenInWindow (from time.Time , until time.Time , parentWallet AccWalletId ) map [AccWalletId ]util.Empty {
1641+ result := map [AccWalletId ]util.Empty {}
1642+
1643+ reports := usageRetrieveHistoricReports (from , until , parentWallet )
1644+ for _ , report := range reports {
1645+ for _ , item := range report .UsageOverTime .Delta {
1646+ if item .Child .Present && item .Change != 0 {
1647+ result [item .Child .Value ] = util.Empty {}
1648+ }
1649+ }
1650+ }
1651+
1652+ return result
16231653}
16241654
16251655func internalRetrieveWallets (
@@ -1669,7 +1699,14 @@ func internalRetrieveWallets(
16691699 }
16701700
16711701 if shouldInclude {
1672- apiWallet := lInternalWalletToApi (now , b , w , owner .WalletOwner (), filter .IncludeChildren )
1702+ apiWallet := lInternalWalletToApi (
1703+ now ,
1704+ b ,
1705+ w ,
1706+ owner .WalletOwner (),
1707+ filter .IncludeChildren ,
1708+ filter .FilterChildrenByIdleTimeInDays ,
1709+ )
16731710 wallets = append (wallets , apiWallet )
16741711 }
16751712
@@ -1730,7 +1767,7 @@ func lRetrieveAncestorWallets(bucket *internalBucket, now time.Time, root AccWal
17301767 var wallets []accapi.WalletV2
17311768 for _ , w := range relevantWallets {
17321769 owner := accGlobals .OwnersById [w .OwnedBy ].WalletOwner ()
1733- wallets = append (wallets , lInternalWalletToApi (now , bucket , w , owner , false ))
1770+ wallets = append (wallets , lInternalWalletToApi (now , bucket , w , owner , false , util . OptNone [ int ]() ))
17341771 }
17351772
17361773 return wallets
0 commit comments