nsfetchedresultscontroller - Enhance my Core Data design. Experts only! -
in acaniusers, i'm downloading closest 20 users me , displaying profile pictures thumbnails in table view. user & photo both resources because each have id
(mongodb bson objectid) on server. each user has unique_id. each photo has 4 different sizes (images) on server: square: 75x75, square@2x: 150x150, large: 320x480, large@2x: 640x960. but, each device have 2 of these sizes, depending on whether it's iphone 3 or 4 (retina display). each of these sizes has own mongodb collection. and, 4 images each photo have same bson objectid's across these 4 collections.
in future, may give user relationship called photos
allow user have more 1 photo. also, although don't foresee this, may add more image sizes (types).
the fresh
attribute on image
tells me whether i've downloaded latest image. set no
whenever photo
's id has changed, , yes after i've finished downloading image.
should store 4 different images in core data or on file system , store urls in core data? read somewhere on 1 or 2mb, should store in file system, not core data. so, thinking of storing square images in core data , large images in file system, i'd rather store them same way make things easier. so, maybe i'll store them in file system? think?
do think should discard 75x75 & 320x480 sizes since pretty iphone 3's gone?
how can improve design of entities, , attributes , relationships. example, resource entity beneficial @ all?
i'm displaying users nsfetchedresultscontroller. however, doesn't know when user's image gets updated, images don't show until scroll aggressively first time. how let nsfetchedresultscontroller know user's thumbnail has finished downloading? have use kvo?
to answer questions:
1 i'd store them in file system , record url in database. i've never been big fan of storing image data in db. plus it'll simplify things little have of image storage uniform. way in image loading code don't have worry if it's type that's stored in db or on file system.
2 no, wouldn't yet. iphone 3 going around bit longer. att still selling them cheap entry level iphone. saw commercial other night advertising them $49.
3 remove resources entry , add id attribute each of classes. how did bad. abstract entities should used when have couple of entities identical , have few differences between them. under hood, core data make 1 table abstract entity , of children. right you're going end 1 table contain both user , photo entries can bad when you're trying query type of entity.
you should delete image entity , move attributes photo entity. photo have values associated , same values won't shared between photos. having them separate entity cause slow down. you'll either need load them photos require join (slow) or they'll loaded 1 @ time when access either data or fresh attributes slow. when each of faults fired in latter scenario separate query , round trip disk happen each object. when loop through pictures display in table, you'll firing n queries instead of 1 can big difference in performance.
4 can use kvo it. have table cell observer user or picture (depends on if have picture added user , changing data or if you're adding new picture user on load completion). when observer gets triggered, update image being displayed.
Comments
Post a Comment