diff options
author | Yorhel <git@yorhel.nl> | 2020-11-09 18:56:40 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-11-09 18:56:43 +0100 |
commit | 14fb7017984473af3f9b0eb4d5d125df44a2f903 (patch) | |
tree | 446b8db8044223ee10e731f0a22d19a2b6c42090 /elm | |
parent | 314c67d81081692b2a1cf77c157fbf10e71ee5d4 (diff) |
imageflag: Add images.c_uids cache + remove tablesample on few images
This fixes spurious "No more images to vote on!" messages when the user
has already voted on almost all images and the tablesample doesn't catch
the few images that they hadn't voted on yet.
Since doing such a select without tablesample is *much* slower, this
needs a more efficient way of finding images the user hadn't voted on
yet, hence the c_uids cache. Still pretty inefficient - it needs a full
table scan - but it'll have to do.
Diffstat (limited to 'elm')
-rw-r--r-- | elm/ImageFlagging.elm | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/elm/ImageFlagging.elm b/elm/ImageFlagging.elm index 0e99f1b5..275f90ec 100644 --- a/elm/ImageFlagging.elm +++ b/elm/ImageFlagging.elm @@ -47,8 +47,9 @@ type alias Model = , changes : Dict.Dict String GIV.SendVotes , saved : Bool , saveTimer : Bool - , loadState : Api.State , saveState : Api.State + , loadState : Api.State + , loadDone : Bool -- If we have received the last batch of images , pWidth : Int , pHeight : Int } @@ -71,6 +72,7 @@ init d = , saveTimer = False , saveState = Api.Normal , loadState = Api.Normal + , loadDone = False , pWidth = d.pWidth , pHeight = d.pHeight } @@ -132,7 +134,7 @@ update : Msg -> Model -> (Model, Cmd Msg) update msg model = let -- Load more images if we're about to run out load (m,c) = - if not m.single && m.loadState /= Api.Loading && Array.length m.images - m.index <= 3 + if not m.loadDone && not m.single && m.loadState /= Api.Loading && Array.length m.images - m.index <= 3 then ({ m | loadState = Api.Loading }, Cmd.batch [ c, GI.send { excl_voted = m.exclVoted } Load ]) else (m,c) -- Start a timer to save changes @@ -158,7 +160,7 @@ update msg model = Desc s v -> ({ model | desc = (s,v) }, Cmd.none) Load (GApi.ImageResult l) -> - let nm = { model | loadState = Api.Normal, images = Array.append model.images (Array.fromList l) } + let nm = { model | loadState = Api.Normal, loadDone = List.length l < 30, images = Array.append model.images (Array.fromList l) } nc = if nm.index < 1000 then nm else { nm | index = nm.index - 100, images = Array.slice 100 (Array.length nm.images) nm.images } in pre (nc, Cmd.none) |