Skip to content

Commit

Permalink
Rip out memcache from Document class
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Mar 3, 2021
1 parent c520b9a commit 2302413
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions src/libraries/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public static function create(
$stmt->bindParam(":content", $content, PDO::PARAM_STR);
$successful = $stmt->execute();
$stmt->closeCursor();
if ($successful) Common::$cache->delete("bnetdocs-documents");
} catch (PDOException $e) {
throw new QueryException("Cannot create document", $e);
} finally {
Expand All @@ -99,10 +98,6 @@ public static function delete($id) {
$stmt->bindParam(":id", $id, PDO::PARAM_INT);
$successful = $stmt->execute();
$stmt->closeCursor();
if ($successful) {
Common::$cache->delete("bnetdocs-document-" . (int) $id);
Common::$cache->delete("bnetdocs-documents");
}
} catch (PDOException $e) {
throw new QueryException("Cannot delete document", $e);
} finally {
Expand All @@ -112,16 +107,6 @@ public static function delete($id) {
}

public static function getAllDocuments( $order = null ) {
$cache_key = 'bnetdocs-documents-' . hash('md5', $order[0] . $order[1]);
$cache_val = Common::$cache->get($cache_key);
if ($cache_val !== false && !empty($cache_val)) {
$ids = explode(",", $cache_val);
$objects = [];
foreach ($ids as $id) {
$objects[] = new self($id);
}
return $objects;
}
if (!isset(Common::$database)) {
Common::$database = DatabaseDriver::getDatabaseObject();
}
Expand All @@ -144,17 +129,11 @@ public static function getAllDocuments( $order = null ) {
if (!$stmt->execute()) {
throw new QueryException('Cannot refresh documents');
}
$ids = [];
$objects = [];
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$ids[] = (int) $row->id;
$objects[] = new self($row);
Common::$cache->set(
'bnetdocs-document-' . $row->id, serialize($row), 300
);
}
$stmt->closeCursor();
Common::$cache->set($cache_key, implode(',', $ids), 300);
return $objects;
} catch (PDOException $e) {
throw new QueryException('Cannot refresh documents', $e);
Expand Down Expand Up @@ -211,9 +190,6 @@ public static function getDocumentsByUserId($user_id) {
$documents = [];
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$documents[] = new self($row);
Common::$cache->set(
"bnetdocs-document-" . $row->id, serialize($row), 300
);
}
$stmt->closeCursor();
return $documents;
Expand Down Expand Up @@ -292,19 +268,6 @@ protected static function normalize(StdClass &$data) {
}

public function refresh() {
$cache_key = "bnetdocs-document-" . $this->id;
$cache_val = Common::$cache->get($cache_key);
if ($cache_val !== false) {
$cache_val = unserialize($cache_val);
$this->content = $cache_val->content;
$this->created_datetime = $cache_val->created_datetime;
$this->edited_count = $cache_val->edited_count;
$this->edited_datetime = $cache_val->edited_datetime;
$this->options_bitmask = $cache_val->options_bitmask;
$this->title = $cache_val->title;
$this->user_id = $cache_val->user_id;
return true;
}
if (!isset(Common::$database)) {
Common::$database = DatabaseDriver::getDatabaseObject();
}
Expand Down Expand Up @@ -340,7 +303,6 @@ public function refresh() {
$this->options_bitmask = $row->options_bitmask;
$this->title = $row->title;
$this->user_id = $row->user_id;
Common::$cache->set($cache_key, serialize($row), 300);
return true;
} catch (PDOException $e) {
throw new QueryException("Cannot refresh document", $e);
Expand Down Expand Up @@ -380,21 +342,6 @@ public function save() {
throw new QueryException("Cannot save document");
}
$stmt->closeCursor();

$object = new StdClass();
$object->content = $this->content;
$object->created_datetime = $this->created_datetime;
$object->edited_count = $this->edited_count;
$object->edited_datetime = $this->edited_datetime;
$object->id = $this->id;
$object->options_bitmask = $this->options_bitmask;
$object->title = $this->title;
$object->user_id = $this->user_id;

$cache_key = "bnetdocs-document-" . $this->id;
Common::$cache->set($cache_key, serialize($object), 300);
Common::$cache->delete("bnetdocs-documents");

return true;
} catch (PDOException $e) {
throw new QueryException("Cannot save document", $e);
Expand Down

0 comments on commit 2302413

Please sign in to comment.