go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/tq/internal/sweep/helpers.go (about) 1 // Copyright 2020 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sweep 16 17 import ( 18 "go.chromium.org/luci/server/tq/internal/partition" 19 "go.chromium.org/luci/server/tq/internal/reminder" 20 ) 21 22 // onlyLeased shrinks the given slice of Reminders sorted by their ID to contain 23 // only ones that belong to any of the leased partitions. 24 func onlyLeased(sorted []*reminder.Reminder, leased partition.SortedPartitions, keySpaceBytes int) []*reminder.Reminder { 25 reuse := sorted[:] 26 l := 0 27 keyOf := func(i int) string { 28 return sorted[i].ID 29 } 30 use := func(i, j int) { 31 l += copy(reuse[l:], sorted[i:j]) 32 } 33 leased.OnlyIn(len(sorted), keyOf, use, keySpaceBytes) 34 return reuse[:l] 35 }