Code Monkey home page Code Monkey logo

Comments (6)

srvrguy avatar srvrguy commented on August 27, 2024

Definite fix for 1.2, although it wouldn't be bad to make a 1.1.1 with that.

Quick logic idea:

When fetching the anime/manga list, we count how many items are returned and compare with our table row count for that type. If our number is larger, truncate the table and re-save. We do this per-type so we don't waste too much time cleaning the other type table if it's not needed. The basic idea behind all this is that the website should be the authority for data.

from atarashii.

AnimaSA avatar AnimaSA commented on August 27, 2024

That would work, though doing that I'm not entirely sure how we would know which entries to remove.

Actually, we can use that to determine if we need to iterate through the data to find out which entries were deleted, but that could bring its own problems (adding and deleting in the same sync would yield same count and then the delete check wouldn't trigger).

The easy way out is check every time, but that's not very efficient is it, this could be trickier than I initially thought.

from atarashii.

srvrguy avatar srvrguy commented on August 27, 2024

Just remove all entries if and only if the item count is different. AFAIK, SQLite supports "truncate", but it does support deletion without a "where" clause, so the way to truncate is:

DELETE FROM [tablename];
VACUUM;

Note that we probably don't need to vacuum, which clears the space used by the table. It's not likely to recover more than a few kilobytes if anything, outweighing the CPU time involved.

If we need to reset autoincrement or anything fancy, the table would need to be dropped and re-created.

from atarashii.

srvrguy avatar srvrguy commented on August 27, 2024

Minor correction. Only remove if the count we get from the web service is less than what we have internally.

The only case I can think where we might have an issue is where an item has been deleted and one or more are added. It would require two syncs to clear that out as our initial count would show more on the web side (thus we don't clean the table) and we save the new items, then when we sync again, we get the count difference and clean the table.

from atarashii.

srvrguy avatar srvrguy commented on August 27, 2024

Another option I thought of that is more elegant:

Add an "synced date" to each item in the table. When we sync against the web service, we put in the current time. After doing a sync, we simply find all rows that haven't been synced on this last run and delete those. Obviously, the only items that wouldn't get the updated timestamp would be ones the service didn't return - deleted items.

from atarashii.

AnimaSA avatar AnimaSA commented on August 27, 2024

That's brilliant, and very easily done too. That's likely what I'll go with. Thanks!

from atarashii.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.