Giter Club home page Giter Club logo

Comments (2)

aicorein avatar aicorein commented on August 17, 2024

这方面我确实没多少研究,但我也简单说一说吧。首先,你说的用数据库有一定可行性。可以用文件系统的钩子,或者一些其他现成的类库,监听文件系统变更,就自动对数据库操作了。除了你说的“跟踪文件路径”的方法,这里我再提供一种方案:

  1. 每个文件对应到一个全文件系统唯一的 id。我建议使用文件一些可以快速读取的属性,例如创建时间等,多组合一些这样的属性,把 id 做成一个可快速计算的 hash 值。当然这样可能有碰撞风险,但是你选的属性足够多、足够特异,这样的概率应该很小。如果你不太会这个,可以找一些类似的哈希算法,或者直接调用 md5 这样的全文摘要计算也可以。
  2. 接下来,所有操作信息与这个 id 对应记录在数据库里。
    • 创建文件时,生成一条 id 为主键的记录;
    • 文件发生操作时,计算文件 id 并更新对应记录的记录值。如果操作后算出来的 id 也变了,那你也可以连着记录的 id 字段一起改;
    • 文件移动时,什么也不用做;
    • 文件删除时,删除这条记录
  3. 注意信息同步。如果你这个程序宕了或者停了,但此时在计算机/服务器上发生了操作,那这些操作就无法同步到数据库。所以每次启动程序,可能需要一个检查同步的操作。
  4. 这个方法可以无视任何移动,但是性能肯定不太好,就看你的应用场景能不能接受了。

如果你觉得这俩方案都比较麻烦,也可以试试在目录建立 git 仓库。git 就有追踪新建、变更、删除的功能。打印次数、下载次数可以用 commit message 或 git notes 的形式记录下来。这个方案甚至可以追踪文件内容的变更。但缺点有两个:一是操作过多,commit 记录可能会堆积成山(考虑定期压缩 commit 记录?);二是大文件对 git 不友好,太多大文件可能影响 git 的性能表现。

from flask-files-server.

ZouJoelin avatar ZouJoelin commented on August 17, 2024

from flask-files-server.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.