-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache goes brrrr
- Loading branch information
Showing
9 changed files
with
225 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,4 +161,5 @@ $RECYCLE.BIN/ | |
|
||
config.yml | ||
videoDownloader | ||
temp/ | ||
temp/ | ||
cache.db |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/bwmarrin/lit" | ||
tele "gopkg.in/telebot.v3" | ||
) | ||
|
||
const cacheTable = "CREATE TABLE IF NOT EXISTS `cache` ( `filename` VARCHAR(15) NOT NULL, `video` TEXT NOT NULL, PRIMARY KEY (`filename`) )" | ||
|
||
func execQuery(query string) { | ||
_, err := db.Exec(query) | ||
if err != nil { | ||
lit.Error("Error executing query, %s", err) | ||
return | ||
} | ||
} | ||
|
||
func load() { | ||
var ( | ||
filename string | ||
bytes []byte | ||
) | ||
|
||
rows, err := db.Query("SELECT filename, video FROM cache") | ||
if err != nil { | ||
lit.Error("Error executing query, %s", err) | ||
return | ||
} | ||
|
||
for rows.Next() { | ||
var video tele.Video | ||
|
||
err = rows.Scan(&filename, &bytes) | ||
if err != nil { | ||
lit.Error("Error scanning row, %s", err) | ||
continue | ||
} | ||
|
||
_ = json.Unmarshal(bytes, &video) | ||
cache[filename] = &video | ||
} | ||
} | ||
|
||
func save(video *tele.Video) { | ||
bytes, _ := json.Marshal(video) | ||
|
||
_, err := db.Exec("INSERT INTO cache (filename, video) VALUES (?, ?)", video.FileName, bytes) | ||
if err != nil { | ||
lit.Error("Error executing query, %s", err) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters