It looks like it works fine.
I found a easy speedup. API accesse are slow if they use the database.
Don't work with owners names but with id. If all calls to PGC_ProfileId2Name() is removes and the id used instead the runtime on me changes from 44 to 7.6 second. Convert in to name in the output in end instead. You will only need 5 api calls
Every time you access a users find you do a PGC_GetFinds() and that is slow
Cache the result in a table and you will get a speedup, code example in the end of this post. I reduced the execution time on me downto 1.3s
Another speedup i did before those it that only consider caches that checked user have found on other caches. Create a associative table with those caches when you process the checked uses caches and add a check if the cache is in that list in the loop over cache owners finds.
That could be be done already when you create the cached version of the owner finds combined with zero the number of finds if the user has less then click size number of find in common with the the checked user
You shll alos remove that user from the list of user but it looks hard in this code or atleast stop all recuve calls for users with to few finds in common
The checker is then fast on most users. It is hard to test because the time depends on the order of your finds and not necessary on the number of finds. That is atlesast true if you get a OK result and i get one on all users i have tested with a log of finds
You have to create
local ownerfinds_caches={}
local userfinds={}
and add the line in the loop of line 31
userfinds[f['gccode']]=f['gccode']
Code to replace the PGC_GetFinds
if ownerfinds_caches[ownerId]==nil then
local tmp=PGC_GetFinds(ownerId, { fields = {'gccode', 'owner_id'}, order = 'OLDESTFIRST', filter = cliqueFilter })
ownerfinds_caches[ownerId]= {}
for _,f in IPairs(tmp) do
if userfinds[f['gccode']] ~= nil then
TableInsert(ownerfinds_caches[ownerId],f)
end
end
if #ownerfinds_caches[ownerId]<=cliqueSize then
ownerfinds_caches[ownerId]={}
end
end
local ownerfinds=ownerfinds_caches[ownerId]