~singpolyma/cheogram

b4549a66632105a46e77c460cee23b0d86445415 — Stephen Paul Weber a month ago b3ceaed
Only query for disco once

Instead of every time we get told a resource is online.  If we already think it
is online, then assume we already queried and just leave well enough alone.

Cuts CPU usage to normal from insane in production.
1 files changed, 6 insertions(+), 3 deletions(-)

M Main.hs
M Main.hs => Main.hs +6 -3
@@ 1087,11 1087,14 @@ component db redis backendHost toRoomPresences toRejoinManager toJoinPartDebounc
					show = maybe mempty mconcat $ elementText <$> child (s"{jabber:component:accept}show") p
					priority = fromMaybe 0 $ (readZ . textToString . mconcat =<< elementText <$> child (s"{jabber:component:accept}priority") p)
					pavailableness = availableness show priority
				in
				in do
				-- We already know about this one?
				exists <- fmap (fromMaybe False . hush) $ Redis.runRedis redis $ Redis.hexists (encodeUtf8 $ bareTxt from) (encodeUtf8 $ maybe mempty strResource $ jidResource from)
				-- Caps?
				case (XML.attributeText (s"ver") =<< caps, XML.attributeText (s"node") =<< caps) of
				case (exists, XML.attributeText (s"ver") =<< caps, XML.attributeText (s"node") =<< caps) of
					(True, _, _) -> log "IGNOREAVAIL" from
				-- Yes: write ver to <barejid>/resource and <cheoagramjid>/resource
					(Just ver, Just node) -> do
					(_, Just ver, Just node) -> do
						let bver = Base64.decodeLenient $ encodeUtf8 ver
						let val = LZ.toStrict $ Builder.toLazyByteString (Builder.word16BE pavailableness ++ Builder.byteString bver)
						Right exists <- Redis.runRedis redis $ do