Skip to content

Commit

Permalink
fix indexes for db
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Mar 31, 2024
1 parent 8ea580e commit a88e9a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ofscraper/api/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def get_after(model_id, username, forced_after=None):
log.debug("Setting date to zero because database is empty")
return 0
missing_items = list(filter(lambda x: x[10] != 1, curr))
missing_items = list(sorted(missing_items, key=lambda x: arrow.get(x[12])))
missing_items = list(sorted(missing_items, key=lambda x: arrow.get(x[11])))
if len(missing_items) == 0:
log.debug("Using last db date because,all downloads in db marked as downloaded")
return operations.get_last_timeline_date(model_id=model_id, username=username)
Expand Down
4 changes: 2 additions & 2 deletions ofscraper/db/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ def media_insert_helper(media, filename, downloaded=None, hash=None, prevData=No
directory = prevData[3]
filename_path = prevData[4]
size = prevData[5]
hash = prevData[13] or hash
hash = prevData[12] or hash
if prevData:
downloaded = prevData[-2] if downloaded == None else downloaded
downloaded = prevData[10] if downloaded == None else downloaded
elif filename:
downloaded = (
pathlib.Path(filename).exists() if downloaded == None else downloaded
Expand Down
11 changes: 6 additions & 5 deletions ofscraper/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,36 +143,37 @@

mediaDupeCheck = """
SELECT media_id,post_id,link,directory,filename,size
,api_type,media_type ,preview,linked,downloaded,created_at
,api_type,media_type ,preview,linked,downloaded,created_at,
hash
FROM medias where media_id=(?)
"""


getTimelineMedia = """
SELECT media_id,post_id,link,directory,filename,size
,api_type,media_type ,preview,linked,downloaded,created_at
,api_type,media_type ,preview,linked,downloaded,created_at,
hash
FROM medias where api_type=('Timeline')
"""

getArchivedMedia = """
SELECT media_id,post_id,link,directory,filename,size
,api_type,media_type ,preview,linked,downloaded,created_at
,api_type,media_type ,preview,linked,downloaded,created_at,
hash
FROM medias where api_type=('Archived')
"""

getMessagesMedia = """
SELECT media_id,post_id,link,directory,filename,size
,api_type,media_type ,preview,linked,downloaded,created_at
,api_type,media_type ,preview,linked,downloaded,created_at,
hash
FROM medias where api_type=('Message') or api_type=('Messages')
"""

mediaUpdate = f"""Update 'medias'
SET
media_id=?,post_id=?,link=?,directory=?,filename=?,size=?,api_type=?,media_type=?,preview=?,linked=?,downloaded=?,created_at=?,hash=?
media_id=?,post_id=?,link=?,directory=?,filename=?,size=?,
api_type=?,media_type=?,preview=?,linked=?,downloaded=?,created_at=?,hash=?
WHERE media_id=(?);"""

mediaTypeUpdate = f"""Update 'medias'
Expand Down

0 comments on commit a88e9a6

Please sign in to comment.