mirror of
https://gitlab.com/mildlyparallel/trashcan.git
synced 2023-04-08 19:00:19 +03:00
print created_at, remove dead code
This commit is contained in:
@@ -286,244 +286,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Select : public Statement {
|
|
||||||
Select(Database &db, const char *sql)
|
|
||||||
: Statement(db, sql)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
uint64_t paper_id;
|
|
||||||
std::string title;
|
|
||||||
std::string first_author;
|
|
||||||
uint64_t year;
|
|
||||||
uint64_t filesize;
|
|
||||||
|
|
||||||
virtual bool load() = 0;
|
|
||||||
|
|
||||||
virtual void write(Serializer &s) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SelectOne : public Select {
|
|
||||||
static const constexpr char *sql =
|
|
||||||
"SELECT "
|
|
||||||
"paper_id, "
|
|
||||||
"title, "
|
|
||||||
"first_author, "
|
|
||||||
"authors, "
|
|
||||||
"year, "
|
|
||||||
"filename, "
|
|
||||||
"filesize, "
|
|
||||||
"filemime, "
|
|
||||||
"created_at, "
|
|
||||||
"updated_at, "
|
|
||||||
"indexed_at, "
|
|
||||||
"doi, "
|
|
||||||
"isbn, "
|
|
||||||
"arxiv, "
|
|
||||||
"bibtex, "
|
|
||||||
"url, "
|
|
||||||
"notes "
|
|
||||||
"FROM Papers "
|
|
||||||
"WHERE Papers.paper_id = ?; ";
|
|
||||||
|
|
||||||
SelectOne(Database &db)
|
|
||||||
: Select(db, sql)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
std::string authors;
|
|
||||||
std::string filename;
|
|
||||||
std::string filemime;
|
|
||||||
uint64_t created_at;
|
|
||||||
uint64_t updated_at;
|
|
||||||
uint64_t indexed_at;
|
|
||||||
std::string doi;
|
|
||||||
std::string isbn;
|
|
||||||
std::string bibtex;
|
|
||||||
std::string arxiv;
|
|
||||||
std::string url;
|
|
||||||
std::string notes;
|
|
||||||
|
|
||||||
inline void bind(uint64_t paper_id)
|
|
||||||
{
|
|
||||||
bind_to(0, paper_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool load()
|
|
||||||
{
|
|
||||||
if (!step())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
load_at(0, paper_id);
|
|
||||||
load_at(1, title);
|
|
||||||
load_at(2, first_author);
|
|
||||||
load_at(3, authors);
|
|
||||||
load_at(4, year);
|
|
||||||
load_at(5, filename);
|
|
||||||
load_at(6, filesize);
|
|
||||||
load_at(7, filemime);
|
|
||||||
load_at(8, created_at);
|
|
||||||
load_at(9, updated_at);
|
|
||||||
load_at(10, indexed_at);
|
|
||||||
load_at(11, doi);
|
|
||||||
load_at(12, isbn);
|
|
||||||
load_at(13, bibtex);
|
|
||||||
load_at(14, arxiv);
|
|
||||||
load_at(15, url);
|
|
||||||
load_at(16, notes);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void write(Serializer &s)
|
|
||||||
{
|
|
||||||
s.write_object(
|
|
||||||
make_pair(PaperId, paper_id),
|
|
||||||
make_pair(Title, title),
|
|
||||||
make_pair(FirstAuthor, first_author),
|
|
||||||
make_pair(Authors, authors),
|
|
||||||
make_pair(Year, year),
|
|
||||||
make_pair(Filename, filename),
|
|
||||||
make_pair(Filesize, filesize),
|
|
||||||
make_pair(Filemime, filemime),
|
|
||||||
make_pair(CreatedAt, created_at),
|
|
||||||
make_pair(UpdatedAt, updated_at),
|
|
||||||
make_pair(IndexedAt, indexed_at),
|
|
||||||
make_pair(Doi, doi),
|
|
||||||
make_pair(Isbn, isbn),
|
|
||||||
make_pair(Bibtex, bibtex),
|
|
||||||
make_pair(Arxiv, arxiv),
|
|
||||||
make_pair(Url, url),
|
|
||||||
make_pair(Notes, notes)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SelectMultiple : public Select {
|
|
||||||
SelectMultiple(Database &db, const char *sql)
|
|
||||||
: Select(db, sql)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
virtual bool load()
|
|
||||||
{
|
|
||||||
if (!step())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
load_at(0, paper_id);
|
|
||||||
load_at(1, title);
|
|
||||||
load_at(2, first_author);
|
|
||||||
load_at(3, year);
|
|
||||||
load_at(4, filesize);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void write(Serializer &s)
|
|
||||||
{
|
|
||||||
s.write_object(
|
|
||||||
make_pair(PaperId, paper_id),
|
|
||||||
make_pair(Title, title),
|
|
||||||
make_pair(FirstAuthor, first_author),
|
|
||||||
make_pair(Year, year),
|
|
||||||
make_pair(Filesize, filesize)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SelectAny : public SelectMultiple {
|
|
||||||
static const constexpr char *sql =
|
|
||||||
"SELECT paper_id, title, first_author, year, filesize "
|
|
||||||
"FROM Papers "
|
|
||||||
"ORDER BY paper_id DESC "
|
|
||||||
"LIMIT ? OFFSET ?;";
|
|
||||||
|
|
||||||
SelectAny(Database &db)
|
|
||||||
: SelectMultiple(db, sql)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void bind(uint64_t limit, uint64_t offset) {
|
|
||||||
bind_to(0, limit);
|
|
||||||
bind_to(1, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SelectByTags : public SelectMultiple {
|
|
||||||
static const constexpr char *sql_part_1 =
|
|
||||||
"SELECT paper_id, title, first_author, year, filesize "
|
|
||||||
"FROM Papers WHERE paper_id IN ( "
|
|
||||||
"SELECT DISTINCT paper_id "
|
|
||||||
"FROM TagLinks "
|
|
||||||
"WHERE tag_id IN (";
|
|
||||||
|
|
||||||
static const constexpr char *sql_part_2 = ") LIMIT ? OFFSET ?);";
|
|
||||||
|
|
||||||
SelectByTags(Database &db, const char *sql)
|
|
||||||
: SelectMultiple(db, sql)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void bind(uint64_t limit, uint64_t offset) {
|
|
||||||
bind_to(0, limit);
|
|
||||||
bind_to(1, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Match : public SelectMultiple {
|
|
||||||
static const constexpr char *sql =
|
|
||||||
"SELECT "
|
|
||||||
"Papers.paper_id, "
|
|
||||||
"Papers.title, "
|
|
||||||
"Papers.first_author, "
|
|
||||||
"Papers.year, "
|
|
||||||
"Papers.filesize "
|
|
||||||
"FROM PapersIndex "
|
|
||||||
"INNER JOIN Papers "
|
|
||||||
"ON "
|
|
||||||
"Papers.paper_id = PapersIndex.paper_id "
|
|
||||||
"AND PapersIndex MATCH ? "
|
|
||||||
"LIMIT ? OFFSET ?";
|
|
||||||
|
|
||||||
Match(Database &db)
|
|
||||||
: SelectMultiple(db, sql)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void bind(const std::string_view &query, uint64_t limit, uint64_t offset) {
|
|
||||||
bind_to(0, query);
|
|
||||||
bind_to(1, limit);
|
|
||||||
bind_to(2, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MatchTags : public SelectMultiple {
|
|
||||||
static const constexpr char *sql_part_1 =
|
|
||||||
"SELECT "
|
|
||||||
"Papers.paper_id, "
|
|
||||||
"Papers.title, "
|
|
||||||
"Papers.first_author, "
|
|
||||||
"Papers.year, "
|
|
||||||
"Papers.filesize "
|
|
||||||
"FROM Papers "
|
|
||||||
"INNER JOIN TagLinks "
|
|
||||||
"ON "
|
|
||||||
"TagLinks.paper_id = PapersIndex.paper_id "
|
|
||||||
"AND TagLinks.tag_id IN (";
|
|
||||||
|
|
||||||
static const constexpr char *sql_part_2 =
|
|
||||||
") "
|
|
||||||
"INNER JOIN PapersIndex "
|
|
||||||
"ON "
|
|
||||||
"Papers.paper_id = PapersIndex.paper_id "
|
|
||||||
"AND PapersIndex MATCH ? "
|
|
||||||
"LIMIT ? OFFSET ?;";
|
|
||||||
|
|
||||||
MatchTags(Database &db, const char *sql)
|
|
||||||
: SelectMultiple(db, sql)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void bind(const std::string_view &query, uint64_t limit, uint64_t offset) {
|
|
||||||
bind_to(0, query);
|
|
||||||
bind_to(1, limit);
|
|
||||||
bind_to(2, offset);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SelecFiledata : public Statement {
|
struct SelecFiledata : public Statement {
|
||||||
static const constexpr char *sql =
|
static const constexpr char *sql =
|
||||||
"SELECT filename, filemime, filesize FROM Papers WHERE paper_id = ?;";
|
"SELECT filename, filemime, filesize FROM Papers WHERE paper_id = ?;";
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public:
|
|||||||
std::string first_author;
|
std::string first_author;
|
||||||
uint64_t year;
|
uint64_t year;
|
||||||
uint64_t filesize;
|
uint64_t filesize;
|
||||||
|
uint64_t created_at;
|
||||||
|
|
||||||
virtual bool load() = 0;
|
virtual bool load() = 0;
|
||||||
|
|
||||||
@@ -59,7 +60,6 @@ public:
|
|||||||
std::string authors;
|
std::string authors;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
std::string filemime;
|
std::string filemime;
|
||||||
uint64_t created_at;
|
|
||||||
uint64_t updated_at;
|
uint64_t updated_at;
|
||||||
uint64_t indexed_at;
|
uint64_t indexed_at;
|
||||||
std::string doi, isbn, arxiv;
|
std::string doi, isbn, arxiv;
|
||||||
@@ -137,6 +137,7 @@ public:
|
|||||||
load_at(2, first_author);
|
load_at(2, first_author);
|
||||||
load_at(3, year);
|
load_at(3, year);
|
||||||
load_at(4, filesize);
|
load_at(4, filesize);
|
||||||
|
load_at(5, created_at);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -148,14 +149,15 @@ public:
|
|||||||
make_pair(Title, title),
|
make_pair(Title, title),
|
||||||
make_pair(FirstAuthor, first_author),
|
make_pair(FirstAuthor, first_author),
|
||||||
make_pair(Year, year),
|
make_pair(Year, year),
|
||||||
make_pair(Filesize, filesize)
|
make_pair(Filesize, filesize),
|
||||||
|
make_pair(CreatedAt, created_at)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SelectAny : public SelectMultiple {
|
struct SelectAny : public SelectMultiple {
|
||||||
static const constexpr char *sql =
|
static const constexpr char *sql =
|
||||||
"SELECT paper_id, title, first_author, year, filesize "
|
"SELECT paper_id, title, first_author, year, filesize, created_at "
|
||||||
"FROM Papers "
|
"FROM Papers "
|
||||||
"ORDER BY paper_id DESC "
|
"ORDER BY paper_id DESC "
|
||||||
"LIMIT ? OFFSET ?;";
|
"LIMIT ? OFFSET ?;";
|
||||||
@@ -172,7 +174,7 @@ public:
|
|||||||
|
|
||||||
struct SelectByTags : public SelectMultiple {
|
struct SelectByTags : public SelectMultiple {
|
||||||
static const constexpr char *sql_part_1 =
|
static const constexpr char *sql_part_1 =
|
||||||
"SELECT paper_id, title, first_author, year, filesize "
|
"SELECT paper_id, title, first_author, year, filesize, created_at "
|
||||||
"FROM Papers WHERE paper_id IN ( "
|
"FROM Papers WHERE paper_id IN ( "
|
||||||
"SELECT DISTINCT paper_id "
|
"SELECT DISTINCT paper_id "
|
||||||
"FROM TagLinks "
|
"FROM TagLinks "
|
||||||
@@ -197,7 +199,8 @@ public:
|
|||||||
"Papers.title, "
|
"Papers.title, "
|
||||||
"Papers.first_author, "
|
"Papers.first_author, "
|
||||||
"Papers.year, "
|
"Papers.year, "
|
||||||
"Papers.filesize "
|
"Papers.filesize, "
|
||||||
|
"Papers.created_at "
|
||||||
"FROM PapersIndex "
|
"FROM PapersIndex "
|
||||||
"INNER JOIN Papers "
|
"INNER JOIN Papers "
|
||||||
"ON "
|
"ON "
|
||||||
@@ -223,7 +226,8 @@ public:
|
|||||||
"Papers.title, "
|
"Papers.title, "
|
||||||
"Papers.first_author, "
|
"Papers.first_author, "
|
||||||
"Papers.year, "
|
"Papers.year, "
|
||||||
"Papers.filesize "
|
"Papers.filesize, "
|
||||||
|
"Papers.created_at "
|
||||||
"FROM Papers "
|
"FROM Papers "
|
||||||
"INNER JOIN TagLinks "
|
"INNER JOIN TagLinks "
|
||||||
"ON "
|
"ON "
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "Logger.hh"
|
#include "Logger.hh"
|
||||||
#include "UserError.hh"
|
#include "UserError.hh"
|
||||||
#include "Request.hh"
|
#include "Request.hh"
|
||||||
|
#include "Config.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <mongoose.h>
|
#include <mongoose.h>
|
||||||
@@ -73,7 +74,7 @@ void Server::listen(const std::string &url)
|
|||||||
{
|
{
|
||||||
assert(!url.empty());
|
assert(!url.empty());
|
||||||
|
|
||||||
logger.info("Listening at", url);
|
logger.info("Listening at", url, "prefix:", TC_API_PREFIX);
|
||||||
|
|
||||||
mg_http_listen(m_mongoose.get(), url.c_str(), &Server::message_callback, this);
|
mg_http_listen(m_mongoose.get(), url.c_str(), &Server::message_callback, this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user