~singpolyma/cheogram

93c0821f36dd365be8e5067c4aaf9ec08a120f2e — Stephen Paul Weber 4 months ago 5eeb670
Only list keys from TC for the rewrite and print progress
2 files changed, 2 insertions(+), 10 deletions(-)

M DB.hs
M Main.hs
M DB.hs => DB.hs +1 -9
@@ 152,15 152,7 @@ hgetall db key = do
foldKeysM :: (HasCallStack) => DB -> Key -> b -> (b -> Key -> IO b) -> IO b
foldKeysM db (Key prefix) z f = do
	keys <- map tcParseKey <$> TC.runTCM (TC.fwmkeys (tcdb db) (tcKey $ Key $ prefix ++ [""]) maxBound)
	z' <- foldM f z (keys :: [Key])
	go keys Redis.cursor0 z'
	where
	pattern = redisKey $ Key $ prefix ++ ["*"]
	go skipKeys cursor acc = do
		(cursor', keys) <- runRedisChecked db $ Redis.scanOpts cursor (Redis.ScanOpts (Just pattern) (Just 100))
		acc' <- foldM f acc $ filter (`notElem` skipKeys) $ map redisParseKey keys
		if cursor' == Redis.cursor0 then return acc' else
			go skipKeys cursor' acc'
	foldM f z (keys :: [Key])

byJid :: JID -> [String] -> Key
byJid jid subkey = Key $ (textToString $ bareTxt jid) : subkey

M Main.hs => Main.hs +1 -1
@@ 2048,7 2048,7 @@ main = do
			toRejoinManager <- atomically newTChan

			log "REWRITE" "DB rewrite..."
			DB.foldKeysM db (DB.Key []) () $ \_ k -> (>> return ()) $ case k of
			DB.foldKeysM db (DB.Key []) 0 $ \n k@(DB.Key s) -> (print (n, s) >>) $ (>> return (n+1)) $ case k of
				DB.Key [_, "muc_membersonly"] -> do
					mvalue <- DB.getEnum db k
					forM_ mvalue $ \value -> if value then