Login About Gallery
List Chunks Sample
COMMENT
Sample on how to break down a large list into smaller chunks - @supermamon for: https://www.reddit.com/r/shortcuts/comments/gd42iy/iterating_over_a_large_list_is_extremely_slow/
COMMENT
create a random list
MATHS
Random number between
10
and
120
SCRIPTING
TEXT
Item
Repeat Index
VARIABLES
Add
Text
to
list
End Repeat
COMMENT
make smaller chunks
COMMENT
set the maximum number of items to process in a batch
NUMBER
25
VARIABLES
Set variable
threshold
to
Number
COMMENT
calculate the number of batches needed to process the whole list
SCRIPTING
Count
Items
in
list
VARIABLES
Set variable
list_size
to
ItemCount
MATHS
list_size
Number
Options Under Construction
MATHS
list_size
-
remainder
Options Under Construction
MATHS
Options Under Construction
MATHS
Options Under Construction
VARIABLES
Set variable
iterations
to
Calculation Result
COMMENT
start processing
NUMBER
1
VARIABLES
Set variable
start
to
Number
SCRIPTING
Repeat
iterations
VARIABLES
Set variable
batch_number
to
Repeat Index
COMMENT
find out which section of the list to process. this will result into the `start` and `end` variables
MATHS
start
+
threshold
Options Under Construction
MATHS
Options Under Construction
VARIABLES
Set variable
end
to
Calculation Result
SCRIPTING
If
end
is greater than
list_size
VARIABLES
Set variable
end
to
list_size
End If
COMMENT
get the portion of the list and process them
SCRIPTING
Get
Items in Range
start
to
end
from
list
SCRIPTING
Repeat with each item in
Item from List
VARIABLES
Set variable
current_item
to
Repeat Item 2
COMMENT
Do what you need to do with the current_item here
TEXT
Batch
Repeat Index 2
# In Batch:
current_item
Item:
batch_number
VARIABLES
Add
Text
to
results
End Repeat
COMMENT
move on to the next batch by adjusting the start index to the next number
MATHS
end
+
1
Options Under Construction
VARIABLES
Set variable
start
to
Calculation Result
End Repeat
TEXT
Combine
results
with
New Lines
TEXT
List Size:
threshold
Threshold:
list_size
Iterations:
Combined Text
iterations

Showcuts

Magic Vars

Screenshot

Submitted Anonymously 18 days ago

Visit iCloud (iOS)

Copy iCloud Link

Scan QR Code

0